Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp312870pxb; Wed, 23 Mar 2022 19:09:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyyRQgq5NI/nlvy3jvs3ysRT2IUjqntu2Hc03M/EMTtYE1S5X2obnBtkO1GbmMAn3Y31nly X-Received: by 2002:a63:8c2:0:b0:380:bfd8:9e10 with SMTP id 185-20020a6308c2000000b00380bfd89e10mr2209753pgi.422.1648087778914; Wed, 23 Mar 2022 19:09:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648087778; cv=none; d=google.com; s=arc-20160816; b=NZM5CqxB+5EIw05FkEBWwG4Xbu5/e2OnM4ND5NbKOmSVHKdSLHJAzstrTvFO8AiN9p 3IDNATozH8PnMst7rvQcTLWGIbIOdzQyVEDoBEQOLiMvkT539D+sXt5ICy38GhTer8Ru NXk0nEeamXVOedo8dflMY5hvUPhtIcmlTtHlbiRRk5eHBvfgOScgWZEAZ8mhPjqNWzq+ IDfXWXdzVjAT3YFHsFxVVuTVxTo2t9XLzTxsI+G4E3eWhcV44HMOWqwKDU14ls28uyED vJb5OIXHLiA/e2zI5sZD07b4Z1GyCf1EmGdQbMhwz2rGx4nSUBy/qZ+rI49pzohs51Ls FOnQ== 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=Scu3z/PeAZ96aNmKdNJtMI7W4oMjSWz8CacLn9QyKg4=; b=LRXEcT9GrsqIKXn1jS6kbjjuwF44QF96t9fpWIdeiGoIxrUN7xnsX7NaZfFSsF4zDE AiPbxM1BaGJjeN2Sy5FWUDVMQerEJ+0dX7BzYrWK6yHeD8AzDoUdL8RDRvH5tZ2QmrVQ 5sugS5le/shUVz44VOaOAe6wSVRYbXdj1PgMGgN79nuVznwk9Jx2wsmQrf0mK25Y8jSC mnmPA7mX04Np/7jL0iYj5j72o/+S8olIzBwCUYQSq4XKpCxnuvY0fosuMxnPQBd5ltpv oK9yic8HIF5eo0bfEY81mx2spxfkAidPcOYCvzsYpsKt2ZvfVVQW9mw7Bb4i73eYQZrR w7vA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=efN7EAMC; 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=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kb5-20020a17090ae7c500b001c7bfb058absi88486pjb.99.2022.03.23.19.09.25; Wed, 23 Mar 2022 19:09:38 -0700 (PDT) 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=@ibm.com header.s=pp1 header.b=efN7EAMC; 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=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238974AbiCWIxy (ORCPT + 99 others); Wed, 23 Mar 2022 04:53:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233417AbiCWIxx (ORCPT ); Wed, 23 Mar 2022 04:53:53 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37C8C72E07; Wed, 23 Mar 2022 01:52:24 -0700 (PDT) Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 22N7frsT021487; Wed, 23 Mar 2022 08:52:23 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=Scu3z/PeAZ96aNmKdNJtMI7W4oMjSWz8CacLn9QyKg4=; b=efN7EAMChPdw30OzP9QigZhgeLerviMU4Iapop4dlMJxZ6x2J98wePS2pyGx4hIZBKJx xJ/pq9my9Pt6VP2veENBUAGeAtY0RKagPQcrohpwJQFFAHcfIFdSONpCg/ZIr3nSXdma 2aY29Yi1m0KcQkyjkHAdvZq1IR8Z+GortQL8o9UcHK/mLneeuyUs1sODoGvt1Nyz5XaY B4bQcgitSqXw9dJ6f/q5p9JiPl7/ljW3qbemHYsgc/j6MUIIMIwVNRVSmqAYjRECtYMy 45bv4eVRGRk++HB1nKb8asP8TQXHoArcOmGlrJYhKjhX1frFFdDBBt/0hP57E+DAMK97 9w== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 3eyyct971c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 23 Mar 2022 08:52:23 +0000 Received: from m0098413.ppops.net (m0098413.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 22N8nxWM029224; Wed, 23 Mar 2022 08:52:22 GMT Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0b-001b2d01.pphosted.com with ESMTP id 3eyyct970t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 23 Mar 2022 08:52:22 +0000 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 22N8lWn5000771; Wed, 23 Mar 2022 08:52:21 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma03fra.de.ibm.com with ESMTP id 3ew6t96xnw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 23 Mar 2022 08:52:20 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 22N8qHZN49480044 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 23 Mar 2022 08:52:17 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B557A11C054; Wed, 23 Mar 2022 08:52:17 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3EB9911C050; Wed, 23 Mar 2022 08:52:17 +0000 (GMT) Received: from [9.171.51.164] (unknown [9.171.51.164]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 23 Mar 2022 08:52:17 +0000 (GMT) Message-ID: <95c28949-8732-8812-c255-79467dafb5c8@linux.ibm.com> Date: Wed, 23 Mar 2022 09:52:16 +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 , Christian Borntraeger , 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> From: Janis Schoetterl-Glausch In-Reply-To: <44618f05-9aee-5aa5-b036-dd838285b26f@linux.ibm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 8xTjBKRm31b552-J35ldxmE7PDwc5q5Q X-Proofpoint-ORIG-GUID: 1I7evJ_plTLTtZFh2YWC_Ye8fnhbccdC 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-22_08,2022-03-22_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 priorityscore=1501 lowpriorityscore=0 mlxscore=0 phishscore=0 adultscore=0 suspectscore=0 bulkscore=0 malwarescore=0 impostorscore=0 spamscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203230049 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 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. > >> 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 >