Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1689237pxj; Wed, 19 May 2021 11:31:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwe96HQTRMZ1owBW/eVBuLF9oNxWryR5CypFPpUMacy2uYACYT/hCYUgygnIni8J0Mz2q8f X-Received: by 2002:a17:906:924a:: with SMTP id c10mr456265ejx.415.1621449079188; Wed, 19 May 2021 11:31:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621449079; cv=none; d=google.com; s=arc-20160816; b=mgm4VeK2ylOFvTlhxv1zXNlJmS5hmwBk/6W7S5InZBGarNDp9rxm9uUkaHaPPPC3iM oiHo1fQWSeZRbAfzPYnjsBg3jXZ5LGDKkBJOJMggi6hC4cqn8ZrRAavIOD+ciygUEwyP i2h9zqi1Sn0zRbk+59KSkaCZfSSGuFQ16BSx9xABerh8ZBXSSGbqiY1NPcNYLKjSZz0V m+qsdTPLeZ1JZeFI2uo+Ok5xXLxdMlqMTsZJeisIZQoUQ91zXyV1dZGs5bFPNhZGguNb zugw76MGr6Xx1X/ADJMMkgH4SoUv8zG4M2yx6+TdQxDZicUp2JPtBJ64I1y+O0LRVL6q HUzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=kLurRiFyhtczUeXHLNIB4esFHRT3cHm8pgOkVCHundQ=; b=VsI0SQhoIarqEdT9MqrxLE4QIm2Abr4eyzvXdEd5Al7FPOsoaeQSt4rm2q3KlR0T5i DVqPcQONliNIM2MmWR4qhQ8rjHkgJye2rBJaOryzHNre5zOn2130iCqAd9MpJwKI8VRv 6mwfLVsgs2AWUvEZhJQfNEcGHqW4MuQOXg7M04ZcEPH+95fGFKdlASlzBmNekWGf+sC9 jKGh2MGE3TxQtP4FF3ByxcdWXxGOzeQWSFNgezJTj0paQoJ/JSeByM7sY3leJnHW4rCv 7dimfN9Bvm+n0VM4GbZHGeXlHLUivt7N7wREnBR3b3P81Ppv8IgdwVOiZefvzERd6FIG 65ZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Wvj2Sqm8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d11si3874418edp.601.2021.05.19.11.30.54; Wed, 19 May 2021 11:31:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Wvj2Sqm8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245144AbhERSS3 (ORCPT + 99 others); Tue, 18 May 2021 14:18:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240163AbhERSS2 (ORCPT ); Tue, 18 May 2021 14:18:28 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A9ACC061573 for ; Tue, 18 May 2021 11:17:09 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id p6so5560534plr.11 for ; Tue, 18 May 2021 11:17:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=kLurRiFyhtczUeXHLNIB4esFHRT3cHm8pgOkVCHundQ=; b=Wvj2Sqm8Ytx2wC43ED+AU1CDqk/+5VvwOusfZRTFz62poKCXIdUKTb7ZSDtdoU6sLB PGQkTLaHMdUtsKySgoaBVfYwePy4Ar7h+Xwt3Lp9utM1FTMQ3qnPLeHTHWwXNo5n1LR1 eVWtBAE9nvK3Fcquxy8AU4EddtTy0EjOuyxU/5smyuVp2grBcFKJkg8zeJDzjXn6HjYq iHiCqVXuLEzGNhNVYIXgV63Bmv9VPB1kXiC0IE3ulSqQJcEZoXTM37Y1TaNaqQmyY83A A53UNbn35mnM8HiVEY0BgREv19AI9r2jCvcL8PUZA0uGwtVeH6bH9xpoIX2o8tJZioVh Hr3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=kLurRiFyhtczUeXHLNIB4esFHRT3cHm8pgOkVCHundQ=; b=QRFyGejsLZnTf0iBg5ROdOcwxCYa/H59sgoh3cWcaVT2Ka8+YH6RoNqh8FHt6QC3PC SXrsYOCQROI+uWtNReTKfeyfGk9EhAElf0CtoYvXYENY+Afh78Y2yGqWJFr+etSQp8KY JxLRMiIUApq8GAX6jx1u788vFOVrgy6ntNKCXYhrojuxXKhltjo7J8qaR4UDUEeL6rCi iQ8YgZOdSgNUAQ5ejNn2BM8cXv6tPZcOL+nRcKUNX7srBIX5owTVzUvI/IaHeYven7jz unYTNmdXuP6yuzJesAJASlbGpepWTv+pV64DHA3yArODVmX3GHc6Doycu+ysEw5MPjNo apBA== X-Gm-Message-State: AOAM532Kj/l0+QuJsTovKvZisZ+qUvjSdF5tWDPBg5v9kYgXecEydGRf 8gSiEeyjC1LS6alkYW+vxmDVOg== X-Received: by 2002:a17:902:7b82:b029:ee:f548:2a18 with SMTP id w2-20020a1709027b82b02900eef5482a18mr6012254pll.75.1621361828613; Tue, 18 May 2021 11:17:08 -0700 (PDT) Received: from google.com (240.111.247.35.bc.googleusercontent.com. [35.247.111.240]) by smtp.gmail.com with ESMTPSA id d10sm9516765pfo.65.2021.05.18.11.17.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 May 2021 11:17:07 -0700 (PDT) Date: Tue, 18 May 2021 18:17:04 +0000 From: Sean Christopherson To: Andi Kleen Cc: Dave Hansen , Kuppuswamy Sathyanarayanan , Peter Zijlstra , Andy Lutomirski , Tony Luck , Kirill Shutemov , Kuppuswamy Sathyanarayanan , Dan Williams , Raj Ashok , linux-kernel@vger.kernel.org Subject: Re: [RFC v2-fix 1/1] x86/tdx: Handle in-kernel MMIO Message-ID: References: <3e9a26c3-8eee-88f5-f8e2-8a2dd2c028ea@intel.com> <20210518004807.258503-1-sathyanarayanan.kuppuswamy@linux.intel.com> <36cd2665-6d8b-9c0b-eec1-25152dcca2a3@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 18, 2021, Andi Kleen wrote: > > Why does this code exist at all? TDX and SEV-ES absolutely must share code for > > handling MMIO reflection. It will require a fair amount of refactoring to move > > the guts of vc_handle_mmio() to common code, but there is zero reason to maintain > > two separate versions of the opcode cracking. > > While that's true on the high level, all the low level details are > different. We looked at unifying at some point, but it would have been a > callback hell. I don't think unifying would make anything cleaner. How hard did you look? The only part that _must_ be different between SEV and TDX is the hypercall itself, which is wholly contained at the very end of vc_do_mmio(). Despite vc_slow_virt_to_phys() taking a pointer to the ghcb, it's unused and thus the function is 100% generic. The ghcb->shared_buffer usage throughout the upper levels can be eliminated by refactoring the stack to take a "u64 *val", since MMIO accesses are currently bounded to 8 bytes. > Besides the bulk of the decoding work is already unified in the common x86 > instruction decoder. The actual actions are different, and the code fetching > is also different Huh? What do you mean by "actual actions"? Why is the code fetch different?