From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA8EEC4363F for ; Wed, 12 May 2021 19:36:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CAE3661289 for ; Wed, 12 May 2021 19:36:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381294AbhELTdw (ORCPT ); Wed, 12 May 2021 15:33:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348913AbhELRjm (ORCPT ); Wed, 12 May 2021 13:39:42 -0400 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58D78C06175F for ; Wed, 12 May 2021 10:38:34 -0700 (PDT) Received: by mail-pg1-x52a.google.com with SMTP id q15so14459536pgg.12 for ; Wed, 12 May 2021 10:38:34 -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=ygukMSZ6mguXZGZCEiXIOEJ1Ou3kN4uMuhJTb1ptDIQ=; b=aXvwhA4SMeZkjzvQvbiETGvNAb2DW9SKROVUAae6HB3DVvXq17O96jqoZbLxV9WKy4 6pxWvKKC9OC18rcxw5IF8aal6YBlmThgbKX5w18PudVXAWgCcMhfEn5QQgzdeqe2JNVO lDDbYBrELxRRY+pM82COQUTEbS52U4d2TK/IIWHJP3+Q+EcRTBiF5L7TGFcRapr4PunV cw91rrN/yQBF9KZmHUWj7OeWzVio3XpBzFn6gR4JIWEWZYDFaVUzCJDUXqX5R5TKlQPR b+bCPrxxd1/ixHoqp72R2BOqR54trN2dX3sUaMjyNtbpMiNWGODg24Cy8qXWN3hmWaT1 JcnA== 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=ygukMSZ6mguXZGZCEiXIOEJ1Ou3kN4uMuhJTb1ptDIQ=; b=sJZEpNYk+ZGr/nLTAfSEKxZGWj8KrHIaO4O0Nky3Aw6OyfVYJk6EC0l2VHp9X9zYQT jjOUQ2KjIGzq/Mksb6tnuGc3JBDEzGkTFqE08XqGx0L1oFYQ6gPy7TaQyi7epXmH29cj 7RcZRbVDNtedKGGFO9rFzo8q8s7iwpclGnYEK8BBRdboQsf2paW67zso1pbzs/imVuw8 oNVe7/vPRoRP0FcE5p5Ak+f1su0qg8zu80w/qwZPulLKxBWYs4xCCC5S2CQiAfG7e2za YVN4uhBsaLwL2YEyHHjSPYg1/hTxTs6eKURmU1xwIH71JnH09u0qBQhyA55o/EjcNzfs qPWA== X-Gm-Message-State: AOAM533xrJhB1u5ZtJPaCsr2zM3/DXMzHm0qZR/xBogtONGXqR32M8Qb AycDgDcRFy6HcURPJkFz0JgEcA== X-Google-Smtp-Source: ABdhPJz7ZGBw/PUTscy3NA7kLlxFOShh6OFXdGf+R8J7hxnn+s1GWr4QOvbmGe5JQFSmOdIskkO9FQ== X-Received: by 2002:aa7:85d0:0:b029:28e:80ff:cbf4 with SMTP id z16-20020aa785d00000b029028e80ffcbf4mr36669418pfn.59.1620841113580; Wed, 12 May 2021 10:38:33 -0700 (PDT) Received: from google.com (240.111.247.35.bc.googleusercontent.com. [35.247.111.240]) by smtp.gmail.com with ESMTPSA id b6sm318783pjk.13.2021.05.12.10.38.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 May 2021 10:38:32 -0700 (PDT) Date: Wed, 12 May 2021 17:38:29 +0000 From: Sean Christopherson To: Joerg Roedel Cc: x86@kernel.org, Hyunwook Baek , Joerg Roedel , stable@vger.kernel.org, hpa@zytor.com, Andy Lutomirski , Dave Hansen , Peter Zijlstra , Jiri Slaby , Dan Williams , Tom Lendacky , Juergen Gross , Kees Cook , David Rientjes , Cfir Cohen , Erdem Aktas , Masami Hiramatsu , Mike Stunes , Martin Radev , Arvind Sankar , linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: Re: [PATCH 4/6] Revert "x86/sev-es: Handle string port IO to kernel memory properly" Message-ID: References: <20210512075445.18935-1-joro@8bytes.org> <20210512075445.18935-5-joro@8bytes.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210512075445.18935-5-joro@8bytes.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 12, 2021, Joerg Roedel wrote: > From: Joerg Roedel > > This reverts commit 7024f60d655272bd2ca1d3a4c9e0a63319b1eea1. > > The commit reverted here introduces a short-cut into the #VC handlers > memory access code which only works reliably in task context. But the > kernels #VC handler can be invoked from any context, making the > access_ok() call trigger a warning with CONFIG_DEBUG_ATOMIC_SLEEP > enabled. > > Also the memcpy() used in the reverted patch is wrong, as it has no > page-fault handling. Access to kernel memory can also fault due to > kernel bugs, and those should not be reported as faults from the #VC > handler but as bugs of their real call-site, which is correctly later > done from vc_forward_exception(). The changelog should call out that a previous patch fixed the original bug by switching to unchecked versions of get/put. Without that, this reads like we're reverting to even worse behavior. Alternatively, and probably even better, fold this revert into the switch to the unchecked version (sounds like those will use kernel-specific flavors?). > Fixes: 7024f60d6552 ("x86/sev-es: Handle string port IO to kernel memory properly") > Cc: stable@vger.kernel.org # v5.11 > Signed-off-by: Joerg Roedel > --- > arch/x86/kernel/sev.c | 12 ------------ > 1 file changed, 12 deletions(-) > > diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c > index 110b39345b40..f4f319004713 100644 > --- a/arch/x86/kernel/sev.c > +++ b/arch/x86/kernel/sev.c > @@ -333,12 +333,6 @@ static enum es_result vc_write_mem(struct es_em_ctxt *ctxt, > u16 d2; > u8 d1; > > - /* If instruction ran in kernel mode and the I/O buffer is in kernel space */ > - if (!user_mode(ctxt->regs) && !access_ok(target, size)) { > - memcpy(dst, buf, size); > - return ES_OK; > - } > - > switch (size) { > case 1: > memcpy(&d1, buf, 1); > @@ -388,12 +382,6 @@ static enum es_result vc_read_mem(struct es_em_ctxt *ctxt, > u16 d2; > u8 d1; > > - /* If instruction ran in kernel mode and the I/O buffer is in kernel space */ > - if (!user_mode(ctxt->regs) && !access_ok(s, size)) { > - memcpy(buf, src, size); > - return ES_OK; > - } > - > switch (size) { > case 1: > if (__get_user(d1, s)) > -- > 2.31.1 >