Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp1468827rwl; Thu, 5 Jan 2023 14:11:11 -0800 (PST) X-Google-Smtp-Source: AMrXdXuQhMj4z3zbuxIPccMkNBa1x6wA7JIpWSCVPFIrt+0tkQ89vPTYShwNsgEezyfrm0iKf/FT X-Received: by 2002:a17:906:d047:b0:78d:f454:ba46 with SMTP id bo7-20020a170906d04700b0078df454ba46mr45460231ejb.69.1672956671645; Thu, 05 Jan 2023 14:11:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672956671; cv=none; d=google.com; s=arc-20160816; b=l0HjeSx3kGAq2hQpgE9+NAOuFjwx6OxDnH1KsI0u6fDYoJx+nI39Ug6hF5/83MJPIo eSxoFeI3L/0hueQWXjCSxHdcXRBoTNB7ZpnDs47OxWoA1LMpnIkAsIBhfjf7I4cLgujL mTL9bC8LyZ9t0HTNTnhsc9uapSkkr3avryYR+mvPyy64Z32wujHvYUgpcdSvLuc2BJfJ gRorb3LrGQSS4M8RhNyCR5bC8f5oauuY/fbjf3YN3cdIpqA2ClOg2Z9Nx1LAAx0ddpaL 9b0+qw31hGXrny+dyM1L4Llp1TWDDNZbreZLsE5Yw4t1Fl2dTUDSTkUie9jFFLzRRza0 GByA== 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=bn7Z6oDABvJGYJVlfHzj/OFR2MilP9KE/xPylqtRaI8=; b=HvgDVgr89LZNdz1/PRLANRD8A5aK9X3Iun+7Ub+3L7bD2StMUep9ZM6p8SNXf2ez1R XpjoXCDzs6Azmw8uyX7eS7D/lN0LW/GiSiYh/K6F1cYmKLS9avvguUpWqlbnS6k5DOqt se5MfGyR07F1T/u4i4JbzqZMbl1P+XpSd3NXD0lNVLJ+YjH/r/Z8nF/oFlMMXFKkaTFM /Po3A5pok5211jIKXAIMeOLXcQa2lzdyqdbZLyfPxnb73yAIWdVdXqHKwoa+Fh5F3xrE 7mz4uV79bnkJukIcN9iSGppq2u3Bou0qUuflfo6+kRpsE/slcWZulo/hroi6j+xN+Agb aCEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=LPsmEqdA; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-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 sh39-20020a1709076ea700b008361e2a67b2si33987447ejc.0.2023.01.05.14.10.43; Thu, 05 Jan 2023 14:11:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto-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=LPsmEqdA; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-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 S234584AbjAEWJf (ORCPT + 99 others); Thu, 5 Jan 2023 17:09:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236139AbjAEWJB (ORCPT ); Thu, 5 Jan 2023 17:09:01 -0500 Received: from mail-oi1-x22f.google.com (mail-oi1-x22f.google.com [IPv6:2607:f8b0:4864:20::22f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B28C36B185 for ; Thu, 5 Jan 2023 14:08:59 -0800 (PST) Received: by mail-oi1-x22f.google.com with SMTP id e205so33128740oif.11 for ; Thu, 05 Jan 2023 14:08: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=bn7Z6oDABvJGYJVlfHzj/OFR2MilP9KE/xPylqtRaI8=; b=LPsmEqdAF17ASsCpSdQFeo9d4yZM+w20RGOPe9inlsD+sZCird0lne6ib9WTiUsoq6 2YgzaklAwt7/d/G7TwXebs7qINP7lo6g4gokBAoTDbEuLNRCPOur2bdGaSB5436CIeQq ow56Fuel0bIs5L34wyTU1If5GO/VcfHRlBWxOg8w8qsR3+7n9GR21BPqtWii9RShhyO4 sK4o0wllJQDfn0fBTBRKdj+90uTkehVGEmVCx2XkcMotlGcWsc49QFRAovOssriMnEgU 2rvFg916i1tZO2H3RWKP5p1gJ4gYmWV4zvrIbxxpj3BvvCGMhW7SujCWmA146HEcnYhg iNbg== 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=bn7Z6oDABvJGYJVlfHzj/OFR2MilP9KE/xPylqtRaI8=; b=X8Oj6wnaJRWa0f81w7yUIR8Bcdz6PfFaiIJsz0kd/GPLwu17dWLTK5x5CK9/5zKFER LIotHNJFqDuz+0SvsLx7tqimcva0uTMntqxX5tfBEPW3YpHKCrS164iKCn29FOYtFpOq 51Sljry7rSIhb/5f3L+jHUZSeJTC8KVyrToG7rbMK91+kJ2tpw6+0wYSxSmp6uf+NsEX C0mN+rf6evDNBrRs7tTXagicMf6NYVn30kvHaC5HsMKTGvQZP2BDESe6UZNwth+OgBOv 6mQnCnsP/afDeKSviejtUlvLrB5d3K51DsOL4bi3V5wLqkjGjr0vUP3Ez2FEDjEJgvDj 5Cmg== X-Gm-Message-State: AFqh2krZ/O7uM3E324N00jWgiXBshBwevS1EOv5JLeMiymxyupFstvQj 13E6sSe2I0eJe5fScLk5gJ4/qn60bluj4UTjmJJYjg== X-Received: by 2002:a05:6808:3947:b0:354:7fd4:f17b with SMTP id en7-20020a056808394700b003547fd4f17bmr2403497oib.221.1672956538794; Thu, 05 Jan 2023 14:08:58 -0800 (PST) MIME-Version: 1.0 References: <243778c282cd55a554af9c11d2ecd3ff9ea6820f.1655761627.git.ashish.kalra@amd.com> <20221219150026.bltiyk72pmdc2ic3@amd.com> In-Reply-To: From: Marc Orr Date: Thu, 5 Jan 2023 14:08: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=-17.6 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,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable 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-crypto@vger.kernel.org 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? 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.