Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp1509935rwl; Thu, 5 Jan 2023 14:54:18 -0800 (PST) X-Google-Smtp-Source: AMrXdXvZD026Y+9vIWGWpTMwPemyNne+xl6f60v/ZykOnDolfAe491hKvO+f4mLuwA7TrNC0EzHW X-Received: by 2002:a17:906:9c8e:b0:7c1:4a3a:dc97 with SMTP id fj14-20020a1709069c8e00b007c14a3adc97mr55954751ejc.0.1672959257932; Thu, 05 Jan 2023 14:54:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672959257; cv=none; d=google.com; s=arc-20160816; b=SiBWYcOTaLSmrcdT+Ai0MHAe7iq6kReG9sD5pOl841Hfd2Sh5ciwcRW8mJa0PumvVN Rya3peMmuJqn0aNXZUSDMZE6Jkdg9tKK3sQd4zYsnCNXO5NEM2iMN+1hZduKzwTgDqiU /8GsYiprtIdFIz2Xrq5ncigzd6qgcwkOqxYuj/8k2jbMG5yIpIL0ecN01IBOBtGXL0uo u1Cjnaa/W/D5zjjn8oaoBc2LUEEHn72E1KKAyG/XsPp+J7AMknGwcSKsaMRf6jCkZ6mu GOHUfnmDmBCHhZ+ji8xFWIUqWwMqtUa9kvFbWc8T3p8MEssM+PEyM8dkm08k502vNIVO VHWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=bzW/w/1hM8B3dAJhNRkp0Jphokn3JFk7Z5V07SJ3Qvg=; b=St/oFDc66NRNx1GNOUS5LIR+18UB4iQEqdQI/cdXtFoKvTxH3F43JGwUmdkxS4uaB1 WedJcAvjxIcFGEqr1u4cwam8dCxT8T6EMNBrJRHNGrXk1agGH6ZtBH7WMaZnxoB1qZql Nomzl1RACPbNgCTBRh056pNn/W8HyEgjxtQwfYLi4Ue/By/9umMAzR4snD5oojnwrT1g ihhIDio0ycttGBNv5+O8q4k41k1BsXfKyi2qS8wUpfumHkSRz0MbQy7tiAivy4e7oCqD 1WiCQd72U56pRleDF3cOqwQr6qdWo27457Dc5yQC84+42fLX5IV4sXq5wXoDZMdJwYSd fAeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=irhVthMk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cy23-20020a0564021c9700b0048a8f268daesi16254690edb.453.2023.01.05.14.54.04; Thu, 05 Jan 2023 14:54:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=irhVthMk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S236052AbjAEWcX (ORCPT + 55 others); Thu, 5 Jan 2023 17:32:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236068AbjAEWcC (ORCPT ); Thu, 5 Jan 2023 17:32:02 -0500 Received: from mail-oa1-x30.google.com (mail-oa1-x30.google.com [IPv6:2001:4860:4864:20::30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BDCD15822 for ; Thu, 5 Jan 2023 14:31:59 -0800 (PST) Received: by mail-oa1-x30.google.com with SMTP id 586e51a60fabf-15085b8a2f7so19750844fac.2 for ; Thu, 05 Jan 2023 14:31:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=bzW/w/1hM8B3dAJhNRkp0Jphokn3JFk7Z5V07SJ3Qvg=; b=irhVthMkbXMEX15iArMrcDY5gNuF5eBvK4eo1OtUylhsmE3IG9S+mrhZxQOiqFOCIp B0NdfYGQgplol+qXFg23OWfulPwvSU6W3PDU1vto6PpvE0VAeFfNIFN4a8ZuHbQY9yux PXeSKyeq3An9rFPoa3fVNGzGEqqWpmTNW/IhDMPZHTEGo5GXlC3tHCL+PpUMhytJ91mi VnE7MFoMeikcgMvkL5CbthLdijfrodW+nJq5InxHQqUSFW5SY7wrPzcsnCf8IgP9ADVl OSDDZsGxvXwBgux7z61kSSUwbOnmCiTQmx5XrBl1LtTxgEFPc4Tdi1LcRhBuf47g7+EW 8CKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=bzW/w/1hM8B3dAJhNRkp0Jphokn3JFk7Z5V07SJ3Qvg=; b=3yuNlRONY6Xg4dXUJhWJDLmmM8wHxSrNA6Rz7EpIR2djtjLW7GZRq59+eSwVrrbeis pMIRFk1uYsEwkTO7VCNdeU4WPm+m9jWPLJ4YXAr288vYuhOSka/VO5OoXohiGOe8bZXF felgGSKwh26CEEdiPZWtji9FHPf5DBx+9Xd9SucsZsGGEd+gvyYKc+HP0Tv3gkvu87pW LCEekGqDfFoW7vq6rRTCO04ZtwEKu/Vyq777gLEycq5a99KAt0LBEueqOqMO6AhB5ONa 1PZwefFk8NCZh6ARCK6hDl/RpaMaW8K9W/HfWe9+7gMzfKdMBVXmJuEJQmuMB1qKE15b vlIQ== X-Gm-Message-State: AFqh2ko5FZ4zFYcz6rjSgtyHzjhndV1rpBhzrfvSNWYWI7I7mafRn/1Q jY2R4evfHJaP7fMIoh6VbGN+3GVtNT9NpUiebHCR1g== X-Received: by 2002:a05:6870:b020:b0:14f:9d87:3d58 with SMTP id y32-20020a056870b02000b0014f9d873d58mr4259851oae.108.1672957918361; Thu, 05 Jan 2023 14:31:58 -0800 (PST) MIME-Version: 1.0 References: <243778c282cd55a554af9c11d2ecd3ff9ea6820f.1655761627.git.ashish.kalra@amd.com> <20221219150026.bltiyk72pmdc2ic3@amd.com> <993e0896-cda6-5033-ad0e-e21508a58077@amd.com> In-Reply-To: <993e0896-cda6-5033-ad0e-e21508a58077@amd.com> From: Marc Orr Date: Thu, 5 Jan 2023 14:31:47 -0800 Message-ID: Subject: Re: [PATCH Part2 v6 07/49] x86/sev: Invalid pages from direct map when adding it to RMP table To: "Kalra, Ashish" Cc: Borislav Petkov , Michael Roth , x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-mm@kvack.org, linux-crypto@vger.kernel.org, tglx@linutronix.de, mingo@redhat.com, jroedel@suse.de, thomas.lendacky@amd.com, hpa@zytor.com, ardb@kernel.org, pbonzini@redhat.com, seanjc@google.com, vkuznets@redhat.com, jmattson@google.com, luto@kernel.org, dave.hansen@linux.intel.com, slp@redhat.com, pgonda@google.com, peterz@infradead.org, srinivas.pandruvada@linux.intel.com, rientjes@google.com, dovmurik@linux.ibm.com, tobin@ibm.com, vbabka@suse.cz, kirill@shutemov.name, ak@linux.intel.com, tony.luck@intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, alpergun@google.com, dgilbert@redhat.com, jarkko@kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-14.3 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,RCVD_IN_SBL_CSS,SPF_HELO_NONE, SPF_PASS,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 5, 2023 at 2:27 PM Kalra, Ashish wrote: > > Hello Marc, > > On 1/5/2023 4:08 PM, Marc Orr wrote: > > On Tue, Dec 27, 2022 at 1:49 PM Kalra, Ashish wrote: > >> > >> Hello Boris, > >> > >> On 12/19/2022 2:08 PM, Borislav Petkov wrote: > >>> On Mon, Dec 19, 2022 at 09:00:26AM -0600, Michael Roth wrote: > >>>> We implemented this approach for v7, but it causes a fairly significant > >>>> performance regression, particularly for the case for npages > 1 which > >>>> this change was meant to optimize. > >>>> > >>>> I still need to dig in a big but I'm guessing it's related to flushing > >>>> behavior. > >>> > >>> Well, AFAICT, change_page_attr_set_clr() flushes once at the end. > >>> > >>> Don't you need to flush when you modify the direct map? > >>> > >> > >> Milan onward, there is H/W support for coherency between mappings of the > >> same physical page with different encryption keys, so AFAIK, there > >> should be no need to flush during page state transitions, where we > >> invoke these direct map interface functions for re-mapping/invalidating > >> pages. > >> > >> I don't know if there is any other reason to flush after modifying > >> the direct map ? > > > > Isn't the Milan coherence feature (SME_COHERENT?) about the caches -- > > not the TLBs? And isn't the flushing being discussed here about the > > TLBs? > > Actually, the flush does both cache and TLB flushing. > > Both cpa_flush() and cpa_flush_all() will also do cache flushing if > cache argument is not NULL. As in this case, no page caching attributes > are being changed so there is no need to do cache flushing. > > But TLB flushing (as PTE is updated) is still required and will be done. Ah, got it now. Thanks for explaining. (I should've looked at the code a bit closer.) > > Also, I thought that Mingwei Zhang found that the > > Milan SEV coherence feature was basically unusable in Linux because it > > only works across CPUs. It does not extend to IO (e.g., CPU caches > > need to be flushed prior to free'ing a SEV VM's private address and > > reallocating that location to a device driver to be used for IO). My > > understanding of this feature and its limitations may be too coarse. > > But I think we should be very careful about relying on this feature as > > it is implemented in Milan. > > > > That being said, I guess I could see an argument to rely on the > > feature here, since we're not deallocating the memory and reallocating > > it to a device. But again, I thought the feature was about cache > > coherence -- not TLB coherence. > > Yes, this is just invalidating or re-mapping into the kernel direct map, > so we can rely on this feature for the use case here. SGTM and that does make sense then. Thanks for confirming.