Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2081584pxb; Fri, 25 Mar 2022 10:44:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx2ZCFeIJ10JBqycCICLnltRqTcncx/zN+m73+pWk1FIBQ6CQkXV2mU4Z5px5QnAoVVAFgY X-Received: by 2002:a05:6a00:3496:b0:4fa:e48e:3d02 with SMTP id cp22-20020a056a00349600b004fae48e3d02mr11501843pfb.26.1648230294477; Fri, 25 Mar 2022 10:44:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648230294; cv=none; d=google.com; s=arc-20160816; b=eOHAWHVv1EWUfg1h4d+0/RhlG6pkwxii+3ipw6xq4s1dsUTgCX7a9BZAoEhorVawyQ WrBHoGTeLtYk4Xhfpb+OgU9SIRGsDiBPSdVcpPyTaA1F6HwjUVGgtk0qY1zRqtmJ1qVH xMAB4nNtHJk8ghqEGKgDNB0yHcBzkg904Dib794U4gGWP1+tTuX9M4G4HbvzYsImWFGj zvzKFqZ8eLKJVhRKid7W7h+LybUcU7pwOraJbUxKmH8CL35d+vxJE9iIy4lRQAk5vxQF 8BOisYjTLCEGEOluyo8v12rlIjLXhM48+BHB+pIHEU4ggxOB1sy2F0+am47t5Y6govJy dKfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=JouOfhBmCn9pvnl66Xpebm/f5DMDoZhzGlnaJC7Pihk=; b=pptAOkSwHT5X8moNv5QEisR3e19b5qCT8jdH9KfJGefqm6Bqb3pOGK0eYIYYBmgp0C xWG9zgn+QZglnTNfaP9BRtHrAQiE9shUmBkUzNKeagTuc6A+FoIHt6yi78V/b5LE4lJo uAQzC5HmWOpqnMDakDs5P1mC7JudX4BXqAUb53ub/3Ii39ktpakPyOc7ViZVivRGU5+i XgOdr6EGGcUaUZ869qZhck7R3Ptv5GEyRbhjrEXNhob9wWAW1orpNf1NmnkhbBltIIX0 hmmb/XDsa0LPM+bvpEt6Y5Fgmho3DaM4n7YA7ErhRsEgrU9T1iOxvc10soq5h+7oGRFc +LAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=fTjLo2TV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id q21-20020a056a00085500b004faa51d7828si3750811pfk.307.2022.03.25.10.44.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 10:44:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=fTjLo2TV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 17908118F5B; Fri, 25 Mar 2022 10:31:24 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238945AbiCWJcN (ORCPT + 99 others); Wed, 23 Mar 2022 05:32:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233726AbiCWJcK (ORCPT ); Wed, 23 Mar 2022 05:32:10 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57BA76C921; Wed, 23 Mar 2022 02:30:41 -0700 (PDT) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 22N8YxRY027388; Wed, 23 Mar 2022 09:30:41 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : date : mime-version : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding; s=pp1; bh=JouOfhBmCn9pvnl66Xpebm/f5DMDoZhzGlnaJC7Pihk=; b=fTjLo2TVEmfky+mt8VP7tKaNg3cM/QTinFYwNtsELAznjy5Jpg3AWm3Rv9399xJHOvwg 2/wuAUxgGo1OCmPIV9B/dGPZgu77kUiR4LAHZnmnxNCD5j9E3pbZdav2jIf+2x9rn32o QYdZpTkIQebcOLAgNfWBluje6XrvjQMtwWR5edmFJaS2YYRqE3kCljC4hKkHnoVzB2xB 3RfjmXYFMHx5lkX+gTa3QwkK7PvjRly73dlio92A7aKZ948XC/WZuAqJSPjv9nfaQ96Z T+mZqMqs9xcB5CYa8Zmy3fiaaG/J3LwnKuLXve+jYl7pNrhBeNeOXD+LBErPEKV81ITF yA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3eyvravub8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 23 Mar 2022 09:30:40 +0000 Received: from m0098409.ppops.net (m0098409.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 22N9UewK031142; Wed, 23 Mar 2022 09:30:40 GMT Received: from ppma04fra.de.ibm.com (6a.4a.5195.ip4.static.sl-reverse.com [149.81.74.106]) by mx0a-001b2d01.pphosted.com with ESMTP id 3eyvravua6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 23 Mar 2022 09:30:40 +0000 Received: from pps.filterd (ppma04fra.de.ibm.com [127.0.0.1]) by ppma04fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 22N9THNP009880; Wed, 23 Mar 2022 09:30:36 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma04fra.de.ibm.com with ESMTP id 3ew6t8q1b7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 23 Mar 2022 09:30:36 +0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 22N9UaF244368134 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 23 Mar 2022 09:30:36 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B630652051; Wed, 23 Mar 2022 09:30:32 +0000 (GMT) Received: from [9.171.50.35] (unknown [9.171.50.35]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 3D6AB52050; Wed, 23 Mar 2022 09:30:32 +0000 (GMT) Message-ID: <968319ed-ae4b-02fe-41c4-06799e940d94@linux.ibm.com> Date: Wed, 23 Mar 2022 10:30:32 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.0 Subject: Re: [PATCH] KVM: s390: Fix lockdep issue in vm memop Content-Language: en-US To: Janosch Frank , Janis Schoetterl-Glausch , Claudio Imbrenda , Heiko Carstens , Vasily Gorbik , Alexander Gordeev Cc: David Hildenbrand , Sven Schnelle , kvm@vger.kernel.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org References: <20220322153204.2637400-1-scgl@linux.ibm.com> <44618f05-9aee-5aa5-b036-dd838285b26f@linux.ibm.com> <95c28949-8732-8812-c255-79467dafb5c8@linux.ibm.com> <7bcd8720-1c92-4e14-0c93-51d604f017a4@linux.ibm.com> From: Christian Borntraeger In-Reply-To: <7bcd8720-1c92-4e14-0c93-51d604f017a4@linux.ibm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: AHC1a6CJhtm_B1XSyEQz9Ea4w891V2ge X-Proofpoint-ORIG-GUID: ZMvIBKup2d96Qntgs3wUx-xIBoeG-kz5 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.850,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-03-23_05,2022-03-22_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 clxscore=1015 priorityscore=1501 lowpriorityscore=0 phishscore=0 spamscore=0 bulkscore=0 adultscore=0 mlxscore=0 impostorscore=0 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203230055 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE 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 Am 23.03.22 um 09:57 schrieb Janosch Frank: > On 3/23/22 09:52, Janis Schoetterl-Glausch wrote: >> On 3/23/22 08:58, Janosch Frank wrote: >>> On 3/22/22 16:32, Janis Schoetterl-Glausch wrote: >>>> Issuing a memop on a protected vm does not make sense, >>> >>> Issuing a vm memop on a protected vm... >>> >>> The cpu memop still makes sense, no? >> >> The vcpu memop does hold the vcpu->lock, so no lockdep issue. >> If you issue a vcpu memop while enabling protected virtualization, >> the memop might find that the vcpu is not protected, while other vcpus >> might already be, but I don't think there's a way to create secure memory >> concurrent with the memop. > > I just wanted you to make this a bit more specific since we now have vm and vcpu memops. vm memops don't make sense for pv guests but vcpu ones are needed to access the sida. Right, I think changing the commit messages - Issuing a memop on a protected vm does not make sense + Issuing a vm memop on a protected vm does not make sense does make sense. > >>> >>>> neither is the memory readable/writable, nor does it make sense to check >>>> storage keys. This is why the ioctl will return -EINVAL when it detects >>>> the vm to be protected. However, in order to ensure that the vm cannot >>>> become protected during the memop, the kvm->lock would need to be taken >>>> for the duration of the ioctl. This is also required because >>>> kvm_s390_pv_is_protected asserts that the lock must be held. >>>> Instead, don't try to prevent this. If user space enables secure >>>> execution concurrently with a memop it must accecpt the possibility of >>>> the memop failing. >>>> Still check if the vm is currently protected, but without locking and >>>> consider it a heuristic. >>>> >>>> Fixes: ef11c9463ae0 ("KVM: s390: Add vm IOCTL for key checked guest absolute memory access") >>>> Signed-off-by: Janis Schoetterl-Glausch >>> >>> Makes sense to me. >>> >>> Reviewed-by: Janosch Frank >>> >>>> --- >>>>    arch/s390/kvm/kvm-s390.c | 11 ++++++++++- >>>>    1 file changed, 10 insertions(+), 1 deletion(-) >>>> >>>> diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c >>>> index ca96f84db2cc..53adbe86a68f 100644 >>>> --- a/arch/s390/kvm/kvm-s390.c >>>> +++ b/arch/s390/kvm/kvm-s390.c >>>> @@ -2385,7 +2385,16 @@ static int kvm_s390_vm_mem_op(struct kvm *kvm, struct kvm_s390_mem_op *mop) >>>>            return -EINVAL; >>>>        if (mop->size > MEM_OP_MAX_SIZE) >>>>            return -E2BIG; >>>> -    if (kvm_s390_pv_is_protected(kvm)) >>>> +    /* >>>> +     * This is technically a heuristic only, if the kvm->lock is not >>>> +     * taken, it is not guaranteed that the vm is/remains non-protected. >>>> +     * This is ok from a kernel perspective, wrongdoing is detected >>>> +     * on the access, -EFAULT is returned and the vm may crash the >>>> +     * next time it accesses the memory in question. >>>> +     * There is no sane usecase to do switching and a memop on two >>>> +     * different CPUs at the same time. >>>> +     */ >>>> +    if (kvm_s390_pv_get_handle(kvm)) >>>>            return -EINVAL; >>>>        if (mop->flags & KVM_S390_MEMOP_F_SKEY_PROTECTION) { >>>>            if (access_key_invalid(mop->key)) >>>> >>>> base-commit: c9b8fecddb5bb4b67e351bbaeaa648a6f7456912 >>> >> >