Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp630761pxv; Thu, 15 Jul 2021 12:00:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzcEEfR+2j1nJzkDFo8tVDPRVHOQSX/AInuqDY7RShi5TIwILZxk/0vxQFz+0UiQshG+qXy X-Received: by 2002:a92:d24d:: with SMTP id v13mr3818463ilg.238.1626375601102; Thu, 15 Jul 2021 12:00:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626375601; cv=none; d=google.com; s=arc-20160816; b=kcYaKC2riEMHKS9OxcOt45ESV+idF8JGQsuPmbyVevOgoFXJ9GJZYRBkyttaqDm7fL /aHT/YO2GgHi/PEaz1nMdYzxRKIbuDPnCDyuF8kYMwtDaf3zEvJn01t7/pwq/gXKU1ml Nq0cZCteQKN5vAD5QWhFz3TTQZbDptyscOyrsNGpclZ1I6EC2eqeXOPLwuuIX5xyqqEg 1Ffw5GOq9xHS1h+q+5Dsizu0qNaaRdkQvsifuju2xQWT38jTQULs/dGTLoAI+CEqoamN lPMXgQGdr/PGzH+lMkIC+Hc4cUIM94OoamI8KYaJZJ7kYJz1l6+FmG/tMdpDgbDVpZnI MhvA== 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=n4/4wnowezgYAcO8PLspC/E18g0vHJpWDQH9C88XPvE=; b=GUHS3q06nXDlbbU/fRu+7np074AtvuBP+2Q33VgAPuVERCSLl/WI1FY4C0qxB+mFpY Iao/77bA+N6FLwjHd74eKldAQ8Q3h12dcmI0siVy0JEEDgPYIH61Tc8XgBejOzvOm9l1 HyyVP5L/U+CI4IM+qz154JwzfQ0pHVVPXuLyrcIQNh5tj7/ERgRLS5iOXqUg1UFYmLFX htfcYsSYjc/Ez64o4Enbp2orRKvNauDyPR5d3HNtQ+c83b4JeJNAFLuOSzC8c/NrqhZZ YUNYb6OAU3MilfZGss4IE9Ju+++2BixbrwPzOdTzWZA31HRRrdfZMd1X4WayNhMoICs4 HGWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=PEYSJW5y; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t11si7733953ils.106.2021.07.15.11.59.40; Thu, 15 Jul 2021 12:00:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-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=PEYSJW5y; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 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 S242674AbhGOTBk (ORCPT + 99 others); Thu, 15 Jul 2021 15:01:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241965AbhGOTAi (ORCPT ); Thu, 15 Jul 2021 15:00:38 -0400 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80BE8C0610DF for ; Thu, 15 Jul 2021 11:56:41 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id k20so7469116pgg.7 for ; Thu, 15 Jul 2021 11:56:41 -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=n4/4wnowezgYAcO8PLspC/E18g0vHJpWDQH9C88XPvE=; b=PEYSJW5ywitp83MZTMzWpoWAjMd6cRgpvN+WoN5IgceUfvr7eYZ+iIY/sdVTeQ4f3z 55r7On1no16MG/cV7wm6lQa+OWP9zu/zlUvwcb1/68aSQhLjTEu92b1Bi0ayZXK9+RDB e4u4LI9SR6fRJj0fTDRUxaYmrVA1qS/Izi32/2SK1zG9NhTviCXYPgH2Y+saYsJgC8II mZDg+jmHoNXhrvWTeqw6JEn+PlxtoP2fB8T8s/O/6xzBaR+p5y4OKdR7077r5EuhbFLZ cgxPO/8BODmINWQNHeTO9uzNEe+l0CEt+ZZenQK9vDBLW5XYwqZ14jMGtdHyw5ktP6JP LtTA== 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=n4/4wnowezgYAcO8PLspC/E18g0vHJpWDQH9C88XPvE=; b=fNHi4deHWnW4M7wi0v2FLrByJR02tbj/hk8D0j1Sterjk1FcsoPduLkBwCBUT/yUlo 2HcPAni7nm/GP4VkgLCDhiMGjPG+O3fzF1g9tZO5fb42PLlXzIfWvRgnxJ+zSmgZB5Ea nNj0feP6cfYNiTZswKJB1bI9YodR2ObnJgcw0Y05iryOp4JL0rRVBJ0k/W5z0R3sGvyE BThlU382Jkx4CaWBZ1wciUn5Y7cRP3ErqBP0TH1E1dvBz/kAOgrDWrVBrIuQcoaFxaMU AcXUMgeWQPBAvyftwS7J1VzNlt3faYjraSWYfG3C9Dlo//ai/z6eRruhKR8gYx1LHc3v repA== X-Gm-Message-State: AOAM5333ufpnpb6yIN5ccA8uAkQVrtrEmb5hKxA5iEW9QV6p8cz3KkjQ LlAohdW4RZJWBKPcEy+z6Ik9og== X-Received: by 2002:a65:614d:: with SMTP id o13mr5988572pgv.351.1626375400818; Thu, 15 Jul 2021 11:56:40 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id r29sm7413174pfq.102.2021.07.15.11.56.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jul 2021 11:56:40 -0700 (PDT) Date: Thu, 15 Jul 2021 18:56:36 +0000 From: Sean Christopherson To: Dave Hansen Cc: Peter Gonda , Brijesh Singh , x86@kernel.org, linux-kernel@vger.kernel.org, kvm list , linux-efi@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-coco@lists.linux.dev, linux-mm@kvack.org, linux-crypto@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Joerg Roedel , Tom Lendacky , "H. Peter Anvin" , Ard Biesheuvel , Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Andy Lutomirski , Dave Hansen , Sergio Lopez , Peter Zijlstra , Srinivas Pandruvada , David Rientjes , Dov Murik , Tobin Feldman-Fitzthum , Borislav Petkov , Michael Roth , Vlastimil Babka , tony.luck@intel.com, Nathaniel McCallum , brijesh.ksingh@gmail.com Subject: Re: [PATCH Part2 RFC v4 06/40] x86/sev: Add helper functions for RMPUPDATE and PSMASH instruction Message-ID: References: <20210707183616.5620-1-brijesh.singh@amd.com> <20210707183616.5620-7-brijesh.singh@amd.com> <8ab309cd-8465-d543-55c8-5f6529fe74fd@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8ab309cd-8465-d543-55c8-5f6529fe74fd@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Mon, Jul 12, 2021, Dave Hansen wrote: > On 7/12/21 11:44 AM, Peter Gonda wrote: > >> +int psmash(struct page *page) > >> +{ > >> + unsigned long spa = page_to_pfn(page) << PAGE_SHIFT; > >> + int ret; > >> + > >> + if (!cpu_feature_enabled(X86_FEATURE_SEV_SNP)) > >> + return -ENXIO; > >> + > >> + /* Retry if another processor is modifying the RMP entry. */ > >> + do { > >> + /* Binutils version 2.36 supports the PSMASH mnemonic. */ > >> + asm volatile(".byte 0xF3, 0x0F, 0x01, 0xFF" > >> + : "=a"(ret) > >> + : "a"(spa) > >> + : "memory", "cc"); > >> + } while (ret == FAIL_INUSE); > > Should there be some retry limit here for safety? Or do we know that > > we'll never be stuck in this loop? Ditto for the loop in rmpupdate. > > It's probably fine to just leave this. While you could *theoretically* > lose this race forever, it's unlikely to happen in practice. If it > does, you'll get an easy-to-understand softlockup backtrace which should > point here pretty quickly. But should failure here even be tolerated? The TDX cases spin on flows that are _not_ due to (direct) contenion, e.g. a pending interrupt while flushing the cache or lack of randomness when generating a key. In this case, there are two CPUs racing to modify the RMP entry, which implies that the final state of the RMP entry is not deterministic. > I think TDX has a few of these as well. Most of the "SEAMCALL"s from > host to the firmware doing the security enforcement have something like > an -EBUSY as well. I believe they just retry forever too.