Received: by 2002:ab2:1347:0:b0:1f4:ac9d:b246 with SMTP id g7csp96012lqg; Wed, 10 Apr 2024 17:12:52 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWP0Ac48yESoyvi0qATizFRdOCAwo/5DJ/Y3DSlx7vx4dzxjIKMW5nUDTid03MI/+cnKswHe6WuurpgaYyAfV9pVuZmIYmO49WQn3Mm2g== X-Google-Smtp-Source: AGHT+IFegKr5q/a68fhSJ0odLdVOAwg7ctSIr7QNMs8DfSreaKX3xOIUEw5NttVqbPK51emIE/gm X-Received: by 2002:a0d:e80c:0:b0:615:ecc:91cb with SMTP id r12-20020a0de80c000000b006150ecc91cbmr4537482ywe.24.1712794372425; Wed, 10 Apr 2024 17:12:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712794372; cv=pass; d=google.com; s=arc-20160816; b=GwLJWYiMA7uGtv/SZ9cPqeoPoc0ORKaD7Gww7rPKvaIEfdiqefWfZrNWJgwao2zm8O aJij9uWC1HW5Zhj1oiCW7xQxevYXFPVfBxGw4RXeziCUUByftaZsvQ2w3yHzBToVHs9N nyJXbIJWon2vsLQ4kA0tTj9I4Ty04kkQWC5y0NN84/ktKLG4n7sRqgDO3MagVC9naTQz 8m5crMJ1sjrwEsQY/7T4M6kxeozw2r/bFNPuL+R3r6KDeKj59qloWXxqoTVZxA0iTgZr iGrrwcRDq0eLuIBq6IIsg+/Hd3Ycf3eNgO3qxZrQMPmDz5xZvraYuEIm3CCpA+HFMUMI BbHQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=QIyaUvQe1Xat3Gv2wtXts1DoFv5C5UbopqhCGzslRuw=; fh=F2WO4afD4K6Q9o/+4WAsLqaNBXnZlNcdTJRVIykRCog=; b=EKp2BEpyHojMAAOx0qFQ/MJyWovkS/ihsHYspH/9U/mSK4UjeC1EeQHKbm2tQbTfUT I91gVj/lttAi46Ylht2CRFtq1YHa5HREtsLqKcKfm688zjAk3SWzEaiG3muYBPuFmBs/ ZJMVHmDqBXQ3tHT/n6ykNJWEUW3CHsc2ook7G7fwY1tCnPTar/ck6g+bkMOQHLW84T4B eLL72HcPMQoxdVR0StIFkS2XoZ6r/Vfg2NpNvBHk/njMeVja94G5QYppWGI6mmLAm7Ut 6grXgnMe4u524/rUnKuxkOI6+Fe0OrKR8kmd6QWKr+Vvla0ty8fWxAKwlHRiVJAt3N10 datw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="L/Imoxcr"; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-139567-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-139567-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id n21-20020a05622a11d500b004317ca0079bsi383976qtk.609.2024.04.10.17.12.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 17:12:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-139567-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="L/Imoxcr"; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-139567-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-139567-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id DA9081C23269 for ; Thu, 11 Apr 2024 00:12:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2311E2BD1C; Thu, 11 Apr 2024 00:08:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="L/Imoxcr" Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D63A02BB1F for ; Thu, 11 Apr 2024 00:08:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712794122; cv=none; b=RuSbFsBVugV6Od27RnG0/WOvsUoeBgtwv9HD6DvP8mDMNU5VNxBmwxDubjEtE7hGqsLyb1uNI/qTOSNs+td+w0AXJ+hCcMoj1/y/NhXSZclYIjfMWXkFlsDxRr+J/VweCiT+CxZm8vKwu0oMqIaJp8yrYSC74HgKj8y9DEIH3sk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712794122; c=relaxed/simple; bh=HvWaHaPle0cX5HGWWdRxWlP3z/kNux1E5mFj4+zTNsM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=occKMq8p36VFkZl+qhLhSytixRHRdkDzev3r9k4tpgp4COIerMe9ZW/7lYA7iMieneISqp38uz8ltWoF22UpK7Lc47CO0dHAHh85TUgKSqdq90jYXxn/trxlNLhQlJUfa65cMN6DKMKEB3uuhzDvzeUZoULsDcx9T5etFCBz1cA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=L/Imoxcr; arc=none smtp.client-ip=209.85.210.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-6ead4093f85so5949837b3a.3 for ; Wed, 10 Apr 2024 17:08:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1712794120; x=1713398920; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QIyaUvQe1Xat3Gv2wtXts1DoFv5C5UbopqhCGzslRuw=; b=L/ImoxcrtT5F9ZRBEoG82N6lIIG75tAnyPE8YX4nqANNGTjblqp3EQjdoG8m8ZOW4d advNjf4EfY4pd5tPSZZ/w3MpzDSHXYMCM0g/TRIergaCyNNTZfpJuWqp3U5XC9UpJcwU nD4Zi0XX5muUd5yQQ489ySvJV5Ilo6v7QtbevqDaqEZLcmOau4tealKBzVdXO099aCdw HfXwfnIb6gLz+S+JrV2rTDkdh6kcd36AMKaQ2XuQAZlOXLDfMQNSk/1zSElTCivn78gU KjR7BRQvp0ba6M/dmPOay5aEBllTFyIhetfuqdgHsR2UvwuzM0EfbqgFSd3X6ZUHpIi7 1UkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712794120; x=1713398920; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QIyaUvQe1Xat3Gv2wtXts1DoFv5C5UbopqhCGzslRuw=; b=NjCvOsCgtDLa/qEWxCqfN89m7K6TL3fx5iWJ8HON2SdA5Ghoa3shRvCh8ejunZFtnc NjE/24cliZLa/1I39uL/JiVTPWrdmf5QmTPMig/E4zVDe1mNAtFgJZEURMyyD/i4bgXd NRtr09zEuN8v782LnGQ8wT28SfwSe0MVGP2RIBvtHrJjVCCCdh5Yq28KnHYckM9InoTL GK5Dlkm4K0ppmlyz8Z26Z+zMCTdOLeAxP5P9bYfVMLmn/K91hln7KRSmnmQ5A24OKYW1 COHi+qPabeukScG0PY3NZN2f8JuxAdZzLnm1neQsY6QkXm7rMsMb0RV5ujs/r9rle/y3 fWUQ== X-Gm-Message-State: AOJu0YzKcmDoZlWXQDeFxY4lq3pJuPBpf4AlvbSGZJ7q/0L+HeqJw394 AXkeTUIenuAWuDV04o6RBF/csmn2ylPJf62yW2kDov3lseh0JOI/D66jcZyZ8IzSMKldIBsrEdi X X-Received: by 2002:a05:6a20:96cc:b0:1a9:8152:511c with SMTP id hq12-20020a056a2096cc00b001a98152511cmr231480pzc.62.1712794119434; Wed, 10 Apr 2024 17:08:39 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id f7-20020a170902684700b001e3d8a70780sm130351pln.171.2024.04.10.17.08.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 17:08:37 -0700 (PDT) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Anup Patel , Ajay Kaher , Albert Ou , Alexandre Ghiti , Alexey Makhalov , Andrew Jones , Atish Patra , Broadcom internal kernel review list , Conor Dooley , Juergen Gross , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Palmer Dabbelt , Paolo Bonzini , Paul Walmsley , Shuah Khan , virtualization@lists.linux.dev, Will Deacon , x86@kernel.org Subject: [PATCH v6 12/24] RISC-V: KVM: No need to exit to the user space if perf event failed Date: Wed, 10 Apr 2024 17:07:40 -0700 Message-Id: <20240411000752.955910-13-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240411000752.955910-1-atishp@rivosinc.com> References: <20240411000752.955910-1-atishp@rivosinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Currently, we return a linux error code if creating a perf event failed in kvm. That shouldn't be necessary as guest can continue to operate without perf profiling or profiling with firmware counters. Return appropriate SBI error code to indicate that PMU configuration failed. An error message in kvm already describes the reason for failure. Fixes: 0cb74b65d2e5 ("RISC-V: KVM: Implement perf support without sampling") Reviewed-by: Anup Patel Signed-off-by: Atish Patra --- arch/riscv/kvm/vcpu_pmu.c | 14 +++++++++----- arch/riscv/kvm/vcpu_sbi_pmu.c | 6 +++--- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/arch/riscv/kvm/vcpu_pmu.c b/arch/riscv/kvm/vcpu_pmu.c index b5159ce4592d..2d9929bbc2c8 100644 --- a/arch/riscv/kvm/vcpu_pmu.c +++ b/arch/riscv/kvm/vcpu_pmu.c @@ -229,8 +229,9 @@ static int kvm_pmu_validate_counter_mask(struct kvm_pmu *kvpmu, unsigned long ct return 0; } -static int kvm_pmu_create_perf_event(struct kvm_pmc *pmc, struct perf_event_attr *attr, - unsigned long flags, unsigned long eidx, unsigned long evtdata) +static long kvm_pmu_create_perf_event(struct kvm_pmc *pmc, struct perf_event_attr *attr, + unsigned long flags, unsigned long eidx, + unsigned long evtdata) { struct perf_event *event; @@ -454,7 +455,8 @@ int kvm_riscv_vcpu_pmu_ctr_cfg_match(struct kvm_vcpu *vcpu, unsigned long ctr_ba unsigned long eidx, u64 evtdata, struct kvm_vcpu_sbi_return *retdata) { - int ctr_idx, ret, sbiret = 0; + int ctr_idx, sbiret = 0; + long ret; bool is_fevent; unsigned long event_code; u32 etype = kvm_pmu_get_perf_event_type(eidx); @@ -513,8 +515,10 @@ int kvm_riscv_vcpu_pmu_ctr_cfg_match(struct kvm_vcpu *vcpu, unsigned long ctr_ba kvpmu->fw_event[event_code].started = true; } else { ret = kvm_pmu_create_perf_event(pmc, &attr, flags, eidx, evtdata); - if (ret) - return ret; + if (ret) { + sbiret = SBI_ERR_NOT_SUPPORTED; + goto out; + } } set_bit(ctr_idx, kvpmu->pmc_in_use); diff --git a/arch/riscv/kvm/vcpu_sbi_pmu.c b/arch/riscv/kvm/vcpu_sbi_pmu.c index 7eca72df2cbd..e1633606c98b 100644 --- a/arch/riscv/kvm/vcpu_sbi_pmu.c +++ b/arch/riscv/kvm/vcpu_sbi_pmu.c @@ -42,9 +42,9 @@ static int kvm_sbi_ext_pmu_handler(struct kvm_vcpu *vcpu, struct kvm_run *run, #endif /* * This can fail if perf core framework fails to create an event. - * Forward the error to userspace because it's an error which - * happened within the host kernel. The other option would be - * to convert to an SBI error and forward to the guest. + * No need to forward the error to userspace and exit the guest. + * The operation can continue without profiling. Forward the + * appropriate SBI error to the guest. */ ret = kvm_riscv_vcpu_pmu_ctr_cfg_match(vcpu, cp->a0, cp->a1, cp->a2, cp->a3, temp, retdata); -- 2.34.1