Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6526403rwb; Mon, 12 Dec 2022 03:08:48 -0800 (PST) X-Google-Smtp-Source: AA0mqf50zk3O0UYNZyGaI5sZNj9IgwU6OyM+TtvrkFSqRUCFtuR26jNldEFeTeDojWb6e6U1UxIX X-Received: by 2002:a17:906:fb02:b0:78d:f454:386d with SMTP id lz2-20020a170906fb0200b0078df454386dmr13431843ejb.42.1670843328202; Mon, 12 Dec 2022 03:08:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670843328; cv=none; d=google.com; s=arc-20160816; b=hgca47zuYXHGpnX3HYPpVAa60lUSHujmo+eSOYFSZcyHhgnI1jcfdxw0sA7H6DeIsD KcjlOSMRWPjeKjXBhXDqEPmyktIXnc3CdCr05vCMqfD1Z45cJXCyAI7TpOL/vRLFN0RS sJaOiMJ4V4sRHeM7yutP173XhRowxR184SDfJu5IABdJp9ylOpONtgsnw3me63JTsI1d Zaizea0DCnD//5x1lI8K9DnTpvnJqYGgrt+IgXrUwbtlQv6KYcsHkHmFyrA3Ntd/oZ0c yCym6xyoccs0TCrFrKPonhsGbnpdwGZn/uhUko1YQ+lghyrJDmKwqO47LEtVULEaXu2B AIBg== 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=0geoJp5y5vah58rc3h1onQRI09PobQgX5h6nKaS34UM=; b=EYXgSgN/uhV8t+qNmvtBXbq7Cq/1EIB5hTQDn80Le3j5uMz2kifpYz5Wh87FPblGhG aXFwuH9xpdVY4K8BhtBp6qpv8yKvQH3gcCGiv3+akyo0TuGddgRvg2YM2aLBrL7n1DWq UGztrn+NSyP/JdLzh2m8lf5mFvTD8dG/UwuCnyQEzOTDp4RZnpjC3vTPXnf04wEpMrTQ uUWBpkkJSIT6iDeUEeBJxdwM7uIt+sPmaDTB8am7tfnD1myYIZVTTwt5kAmc2GIy8f2+ tmHvlc0MhSp/lsHt2XG7WEJ7LhKBAhLmIJ0zfPosGEEVagB1mtjA9KzpFiKxphmaT5eS ugIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="UTOG3Xn/"; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id my12-20020a1709065a4c00b007c0dcc41dbasi4560189ejc.879.2022.12.12.03.08.29; Mon, 12 Dec 2022 03:08:48 -0800 (PST) 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=@redhat.com header.s=mimecast20190719 header.b="UTOG3Xn/"; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232381AbiLLKqe (ORCPT + 75 others); Mon, 12 Dec 2022 05:46:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232262AbiLLKoc (ORCPT ); Mon, 12 Dec 2022 05:44:32 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4903D6247 for ; Mon, 12 Dec 2022 02:38:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670841531; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0geoJp5y5vah58rc3h1onQRI09PobQgX5h6nKaS34UM=; b=UTOG3Xn/nlg2q5g1qlid6ooLJSUp4MOnsRQ2oiC+heTNWT49l+JHO9dAlk71/0cGNquz23 I6NAYQi7HU72xSahX5wZOXaw3XLgREdagPv/q6ixINYFoktSo2Foo/WMRh9M+q4f88w+Wt hJmlqxhHLbWCutnwNV/8yOv/azOI8G8= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-86-ZJNAIMnlPlWTX2OA-sG3Mg-1; Mon, 12 Dec 2022 05:38:50 -0500 X-MC-Unique: ZJNAIMnlPlWTX2OA-sG3Mg-1 Received: by mail-wm1-f69.google.com with SMTP id b47-20020a05600c4aaf00b003d031aeb1b6so3974379wmp.9 for ; Mon, 12 Dec 2022 02:38:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=0geoJp5y5vah58rc3h1onQRI09PobQgX5h6nKaS34UM=; b=oi/cCaj1nFEDNQRg1PPIogZ6n1HTlQ3oDcnz4LJQRIRI2/RDK3vNCrk9RczwNvepDm mmIGxxOZGrZkv4DJZK7+Pgmk/3VxtGKmMeACpX+7/Eyx4GqDU8acV7dq0weAncdCrYP7 tTKqdBl1WFaootlpPm+tEaafCG4CWlUn0HjUQXuV+imjNZoLU3yZl9E5V9y0CWjOa1qN 2EUMm5ucAfozsn0vNslt4Q4gTmFRPL2GFkaZWFqJKU/xrPEWb0JLSTQo0X++zwYd8IIs Yg0YLspTgzyOcHWFYokm7uicnPYIqbu8C6ktswh5NC0XbYA431kj9o2p1mPGBW6nJZRL +34Q== X-Gm-Message-State: ANoB5pk5sOHz1i0o3j9IQhjST0E8dNfVFhrJFQiBvG3xU9LgtoNn+/Gg bEMfnRqVxhdv1gojdTtiIi6nLuOxFcLA8wZ35e9KrRbqDt/1AhSK/KZZcUUBMVNy616hrvLDGPx t2g7uulTJ4etwkVQC51IEke+X X-Received: by 2002:a05:600c:5398:b0:3cf:d0b1:8aa1 with SMTP id hg24-20020a05600c539800b003cfd0b18aa1mr12355049wmb.0.1670841528987; Mon, 12 Dec 2022 02:38:48 -0800 (PST) X-Received: by 2002:a05:600c:5398:b0:3cf:d0b1:8aa1 with SMTP id hg24-20020a05600c539800b003cfd0b18aa1mr12355032wmb.0.1670841528795; Mon, 12 Dec 2022 02:38:48 -0800 (PST) Received: from ?IPV6:2001:b07:6468:f312:9af8:e5f5:7516:fa89? ([2001:b07:6468:f312:9af8:e5f5:7516:fa89]) by smtp.googlemail.com with ESMTPSA id iw3-20020a05600c54c300b003d220ef3232sm5442368wmb.34.2022.12.12.02.38.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 12 Dec 2022 02:38:48 -0800 (PST) Message-ID: <2ce6eab8-6156-1282-bf29-87fd74e4587a@redhat.com> Date: Mon, 12 Dec 2022 11:38:47 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: Re: [PATCH v2 7/7] KVM: selftests: Avoid infinite loop if ucall_alloc() fails Content-Language: en-US To: Sean Christopherson , Oliver Upton Cc: Marc Zyngier , James Morse , Alexandru Elisei , Shuah Khan , Andrew Jones , Peter Gonda , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, kvmarm@lists.linux.dev, Ricardo Koller , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org References: <20221209015307.1781352-1-oliver.upton@linux.dev> <20221209015307.1781352-8-oliver.upton@linux.dev> From: Paolo Bonzini In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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-kernel@vger.kernel.org On 12/9/22 22:03, Sean Christopherson wrote: > From: Sean Christopherson > Date: Fri, 9 Dec 2022 12:55:44 -0800 > Subject: [PATCH] KVM: selftests: Use magic value to signal ucall_alloc() > failure > > Use a magic value to signal a ucall_alloc() failure instead of simply > doing GUEST_ASSERT(). GUEST_ASSERT() relies on ucall_alloc() and so a > failure puts the guest into an infinite loop. > > Use -1 as the magic value, as a real ucall struct should never wrap. > > Reported-by: Oliver Upton > Signed-off-by: Sean Christopherson > --- > tools/testing/selftests/kvm/lib/ucall_common.c | 16 ++++++++++++++-- > 1 file changed, 14 insertions(+), 2 deletions(-) > > diff --git a/tools/testing/selftests/kvm/lib/ucall_common.c b/tools/testing/selftests/kvm/lib/ucall_common.c > index 0cc0971ce60e..2f0e2ea941cc 100644 > --- a/tools/testing/selftests/kvm/lib/ucall_common.c > +++ b/tools/testing/selftests/kvm/lib/ucall_common.c > @@ -4,6 +4,8 @@ > #include "linux/bitmap.h" > #include "linux/atomic.h" > > +#define GUEST_UCALL_FAILED -1 > + > struct ucall_header { > DECLARE_BITMAP(in_use, KVM_MAX_VCPUS); > struct ucall ucalls[KVM_MAX_VCPUS]; > @@ -41,7 +43,8 @@ static struct ucall *ucall_alloc(void) > struct ucall *uc; > int i; > > - GUEST_ASSERT(ucall_pool); > + if (!ucall_pool) > + goto ucall_failed; > > for (i = 0; i < KVM_MAX_VCPUS; ++i) { > if (!test_and_set_bit(i, ucall_pool->in_use)) { > @@ -51,7 +54,13 @@ static struct ucall *ucall_alloc(void) > } > } > > - GUEST_ASSERT(0); > +ucall_failed: > + /* > + * If the vCPU cannot grab a ucall structure, make a bare ucall with a > + * magic value to signal to get_ucall() that things went sideways. > + * GUEST_ASSERT() depends on ucall_alloc() and so cannot be used here. > + */ > + ucall_arch_do_ucall(GUEST_UCALL_FAILED); > return NULL; > } > > @@ -93,6 +102,9 @@ uint64_t get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc) > > addr = ucall_arch_get_ucall(vcpu); > if (addr) { > + TEST_ASSERT(addr != (void *)GUEST_UCALL_FAILED, > + "Guest failed to allocate ucall struct"); > + > memcpy(uc, addr, sizeof(*uc)); > vcpu_run_complete_io(vcpu); > } else { > > base-commit: dc2efbe4813e0dc4368779bc36c5f0e636cb8eb2 > -- Queued, thanks. Paolo