From patchwork Fri Dec 9 01:53:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 31590 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp529958wrr; Thu, 8 Dec 2022 17:58:28 -0800 (PST) X-Google-Smtp-Source: AA0mqf7eDp1l/OAkBb0263jxc/qpI/KzUgfQq9UHFzR6v1MwnetK5vj9H61ZLheO5R/c+VD0IoBP X-Received: by 2002:a17:907:3e14:b0:7c0:f719:838d with SMTP id hp20-20020a1709073e1400b007c0f719838dmr4573645ejc.36.1670551108753; Thu, 08 Dec 2022 17:58:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670551108; cv=none; d=google.com; s=arc-20160816; b=jVDZVRBGPTYa2iLDMByjAhMsQv78hK8ZTP7QCw1LN439K1zuvwYtsTqJOUvZnkoH8n vI9iAEi6GaiY5m9VPoa2snEJy5ZkbabZTya6rX19LVGx/2/WpIAwpikm0OQLieNXj13P k/79TvE1hwc/TNA+iyNDQ6ia/2vBpSsNDo0Ej+G2RMpmeiEW4HJUX8O5wRzBpulSESZ2 9P42AH7E9OY01CPBifUK4zVIcMmjX3tpR7Z/jbKMvTuwOKWzjjrbPQERgncDqNL6B1Ye iyZPv5Gvx+yTDz3D3QO8pyDt9xaqlPNNQVQml8xRNjnMc9YBwa7I4ZBMaNjoftgXRnah biVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=iGqzh1nn8M8qIu2HMX7NJCgwvQUB1383Z9Wplc2q4DE=; b=tKAveaWpebKHbCoa0WXrsjzKDBM2gcpE4xEitsMVA3dDa2oHz/gdnqHWIsvAk+uBaq I8Tdur7NKksekpmmZ8m3vfkS34rRCFl20OKtyUcp+yvQwXmU6Tul4ippVuAbGyH9/Jby ptYdJS7JAKD7wgnmcbBMyv5vLvN06X7CJkH0vDXIoiF/dHJSiZTec5HrDD/fjl9h3VU6 ugLR56IVr1X8IYtfUvnizSbQupG9ju6/LpkxxMbutb/bgmuRwuUe1Jbwch/5knq6dCUa O5Gn4bEYD8pJzJcsvKX+KLbBgNXSRbFZJlbG0JwWWQ2Gs3kefaSecVT5vEXoZwy8qZcn l5eQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hx9-20020a170906846900b007c10a0c590dsi72518ejc.25.2022.12.08.17.58.05; Thu, 08 Dec 2022 17:58:28 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230048AbiLIByk (ORCPT + 99 others); Thu, 8 Dec 2022 20:54:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230129AbiLIByG (ORCPT ); Thu, 8 Dec 2022 20:54:06 -0500 Received: from out-74.mta0.migadu.com (out-74.mta0.migadu.com [91.218.175.74]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE657B1066 for ; Thu, 8 Dec 2022 17:53:48 -0800 (PST) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: Marc Zyngier , James Morse , Alexandru Elisei , Paolo Bonzini , Shuah Khan , Andrew Jones , Peter Gonda , Sean Christopherson Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, kvmarm@lists.linux.dev, Ricardo Koller , Oliver Upton , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 7/7] KVM: selftests: Avoid infinite loop if ucall_alloc() fails Date: Fri, 9 Dec 2022 01:53:06 +0000 Message-Id: <20221209015307.1781352-8-oliver.upton@linux.dev> In-Reply-To: <20221209015307.1781352-1-oliver.upton@linux.dev> References: <20221209015307.1781352-1-oliver.upton@linux.dev> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751699799672183925?= X-GMAIL-MSGID: =?utf-8?q?1751699799672183925?= Guest assertions depend on successfully allocating a ucall structure. As such, the use of guest assertions when ucall_alloc() fails simply leads to an infinite loop in guest code. Use GUEST_UCALL_NONE() to indicate failure instead. Though not technically necessary, use a goto to have a single callsite and an associated comment about why assertions don't work here. It isn't perfect, at least the poor developer gets some signal out of the guest... Fixes: 426729b2cf2e ("KVM: selftests: Add ucall pool based implementation") Signed-off-by: Oliver Upton Reported-by: Oliver Upton Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/lib/ucall_common.c | 12 ++++++++++-- 1 file changed, 10 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..e8370da3de24 100644 --- a/tools/testing/selftests/kvm/lib/ucall_common.c +++ b/tools/testing/selftests/kvm/lib/ucall_common.c @@ -41,7 +41,8 @@ static struct ucall *ucall_alloc(void) struct ucall *uc; int i; - GUEST_ASSERT(ucall_pool); + if (!ucall_pool) + goto out; for (i = 0; i < KVM_MAX_VCPUS; ++i) { if (!test_and_set_bit(i, ucall_pool->in_use)) { @@ -51,7 +52,14 @@ static struct ucall *ucall_alloc(void) } } - GUEST_ASSERT(0); +out: + /* + * If the guest cannot grab a ucall structure from the pool then the + * only option to get out to userspace is a bare ucall. This is probably + * a good time to mention that guest assertions depend on ucalls with + * arguments too. + */ + GUEST_UCALL_NONE(); return NULL; }