Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp2119173lqa; Tue, 30 Apr 2024 08:36:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUvYieYNQRhlbUVT6FKRvBicyktEFLFv8Xja2zrbkeDYdgfpqntoHuNWe0TMKvWXWHwgJWPPszpASIqlaQhUnAiCkx2j7YKDB7bLuX+DQ== X-Google-Smtp-Source: AGHT+IFM5H+xhKiBdGCz7kHTWKx350CpBYsC9WGMTUW2hZyGqX+tMGUQjvgtsqU+PmN83JapTWOf X-Received: by 2002:a05:6808:492:b0:3c8:4228:e6d4 with SMTP id z18-20020a056808049200b003c84228e6d4mr14233768oid.9.1714491382361; Tue, 30 Apr 2024 08:36:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714491382; cv=pass; d=google.com; s=arc-20160816; b=Q8TQAx8+jwm0dXIA7UukVzeQFo8ZaCpzFuPAOfJiWyWz6HgDBTbdUQLc2+M+XLhzKF KVazt45goViNQc69+E0S/pV3A7v4uNfN9vmGw4Mr697kyhyjtmyaU8HBnN+kNxEI1Cv+ +GaW9uIOY8nHpkySK0tb1JAbmUYrDiUGGd26lm+IXaxULbcVOjkHlq6QkGKPJcLSXiPf 8RubMxvDtOaJVDDUfLeeq2PqOFKWOv2ZOFBDR0Xh/doCz1gAQR3VVs2S+lyL9tXxifb6 1gLcu3vKfoJkewRpn54MG48gqhNxXukBic8KTuLHPpo5QXVyKbYlU9NXAoaJTOusgUdk 3ezA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=HKIJbDUVjXcCbxtnsr2n+MGPFjkYZK2XnzHwiA9YwSY=; fh=O+94IMaAk/O9zgk4P7oWnQr+V5DAWooCaTsIAe2ZIIo=; b=UyyqTSTo5CzdNAq9fYO3iPOVN91v35ADBSzOlVA+PrLVCwJkNe8TbmEv9ZtqVHX0UP CvbilQ4G/dJV1EfmG1MES0dXDFqhDnDF8u+QI3HYv8NLBT5brFgRlcUtTh+/zJXg2LrZ E3JzlOqnp09hVHiZNxRBwHQ1wjz+MgVJHWWvjjikoi4RT/n33xHcGQuzU/sLVhMoXzsa 4b1a7pXU/4BWLqJD6mLqhzfBfAf5w0lTG4itmWbNNK3HjoPElXUNQkFneYvfYFZYbGOr nvxgqB6FK5TrS4EactJVRrFR6+oisJiamLK8af4I68YalQHNWWU8fKlmIwBQokf6sN8X lJyw==; 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=rY4nvTaq; 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-164288-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-164288-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 hg23-20020a05622a611700b00434733fedafsi28065335qtb.456.2024.04.30.08.36.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 08:36:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-164288-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=rY4nvTaq; 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-164288-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-164288-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 1721E1C24392 for ; Tue, 30 Apr 2024 15:36:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3127F175550; Tue, 30 Apr 2024 15:35:42 +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="rY4nvTaq" Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (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 A8877172BDA for ; Tue, 30 Apr 2024 15:35:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714491341; cv=none; b=gmf7PfTN72DvevSliB+0jeSKG3c/EBhRjCzsjudtgHl8dGM7RbHLwioW+ODxy8ZTbrtY5WUn4mmH6JBP6tq61n4lYZWHbr9SbIVyMXeMlETVeBMpMAK08UlVEqZZyu0ynvXuIQOFyNGE961zT4zBZVyXkIZkPbkC8CgO9m3o2c0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714491341; c=relaxed/simple; bh=3BFwiOHCYaU38l0ewgMfQbgWxwkzbz05CkINxTEtWKw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=rnddRGlZkOVizLPY/9yR7twWGDkrdgUV+LTqr4SeBfb3Xh6gjufcYWckG05TIrBAJBeFnCsdCe2WrsN5/3DaH3KWn4/Po1CNHpLztciFx0PtVDjvtEo/Q7+t3llN9u25RBC/yW5qju6uOH8zPOWKwxeHwsdkw+U+Ky9llmRTmBQ= 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=rY4nvTaq; arc=none smtp.client-ip=209.85.221.41 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-wr1-f41.google.com with SMTP id ffacd0b85a97d-34a42d6e216so1300119f8f.1 for ; Tue, 30 Apr 2024 08:35:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1714491338; x=1715096138; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=HKIJbDUVjXcCbxtnsr2n+MGPFjkYZK2XnzHwiA9YwSY=; b=rY4nvTaqH8hzNVdqnIW6pdl9Eo2IqzLwDKpzAbvIDGdL+VmnAslLu8zKAfFkvCMDIF e7+Ki7rqESmZK0w8iP39mlpqZSDY+lLxfhZGEwZz7t5YU5Fvm7lMDRH3edSL/574CoKt zPwm4HU1YUitjsmjsbW5PYmq8QkeNxhJq145vQoMdBNmrNTkTJqB3mS3NNDAwkYBQ1DS tdn4FAL+CblIKsJtUleoeqWE4milxk2EHWtKoicfWm9CV5nb33NKL/H7TNK+NFFicRLz jhHSErE2lYfgNVp7NWZLHG3tfUV1PrNQylDPcXuNvbNF95n++z5kCb3y0ESk7U/DC8Yd tI3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714491338; x=1715096138; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=HKIJbDUVjXcCbxtnsr2n+MGPFjkYZK2XnzHwiA9YwSY=; b=Jk3rh2HYJ5S7JLhuzIaiSGKwMjXqbUz8ZioeveiV4lS3LZWJ6c9b9/irrR40s0iIkw Ba1REzVzgbN//LHcx9+6UQHGqOm6FNTi9gtmGyaAt89o/00Ee9O4Sf/WDiu2vRO5TreX NlarY6hKPl2Z2LaFdABX41E/OgdEhloP3S0tjnNH2aZGHRcJ0QKs120qguhd2YTJZ/Ci qb0e+lJFphTSqXkp+9pzkAHT/UXheOyFM14D6t5NamxGx1axdtX+BpCuNYE+ccXfr3CT wrdWLVkrdnlBR49nnAdyPQ8UoKAQsElwiHqZdmYPHOT+VErPqeBcfdzBn24b5aVU1Dg3 qmXg== X-Forwarded-Encrypted: i=1; AJvYcCXY/sLRhkZIGEj5uZj3QhSnsv2yTeWKpxxlOahaSn3qzO8EDa4UrbaPZMFsdpCLqnKR68NtZW8qJBzYcEklRFMxDvkWXczwj3Ww6Wpa X-Gm-Message-State: AOJu0YxbCqP+9XZba8ssHPKAmXuPx7kw7PTQSM3kWMBWAKaFrEke9ZXe CJ/uCyuhAsbGlJu6jbsUDJTEiErLb2Dpj4eDAE1mhyn774iDOxCkNn7vbmOOpG4= X-Received: by 2002:adf:ed4b:0:b0:34d:a29d:a8d5 with SMTP id u11-20020adfed4b000000b0034da29da8d5mr19585wro.4.1714491337672; Tue, 30 Apr 2024 08:35:37 -0700 (PDT) Received: from ?IPV6:2a01:e0a:999:a3a0:c21b:67fd:90ab:9053? ([2a01:e0a:999:a3a0:c21b:67fd:90ab:9053]) by smtp.gmail.com with ESMTPSA id r30-20020adfb1de000000b00343e392829dsm32637498wra.97.2024.04.30.08.35.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 30 Apr 2024 08:35:37 -0700 (PDT) Message-ID: Date: Tue, 30 Apr 2024 17:35:36 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH 7/7] RISC-V: KVM: add support for double trap exception To: Deepak Gupta Cc: Conor Dooley , Rob Herring , Krzysztof Kozlowski , Paul Walmsley , Palmer Dabbelt , Albert Ou , Anup Patel , Atish Patra , linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, Ved Shanbhogue References: <20240418142701.1493091-1-cleger@rivosinc.com> <20240418142701.1493091-8-cleger@rivosinc.com> Content-Language: en-US From: =?UTF-8?B?Q2zDqW1lbnQgTMOpZ2Vy?= In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 27/04/2024 03:33, Deepak Gupta wrote: >> /** >>  * kvm_riscv_vcpu_trap_redirect -- Redirect trap to Guest >>  * >>  * @vcpu: The VCPU pointer >>  * @trap: Trap details >>  */ >> -void kvm_riscv_vcpu_trap_redirect(struct kvm_vcpu *vcpu, >> -                  struct kvm_cpu_trap *trap) >> +int kvm_riscv_vcpu_trap_redirect(struct kvm_vcpu *vcpu, >> +                 struct kvm_cpu_trap *trap) >> { >>     unsigned long vsstatus = csr_read(CSR_VSSTATUS); >> >> +    if (riscv_isa_extension_available(vcpu->arch.isa, SSDBLTRP)) { >> +        if (vsstatus & SR_SDT) >> +            return kvm_riscv_double_trap(vcpu, trap); >> + >> +        /* Set Double Trap bit to enable double trap detection */ >> +        vsstatus |= SR_SDT; > > I didn't get it. > Why do this without checking if current config allows us to do so ? > I am imagining we do this only when henvcfg for current vcpu says that > DTE=1 > for this this guest, right? We actually do not really care since if not enabled, this bit will be masked by the hardware when writing it to the CSR. I could indeed add a check for that but in the end, it will yield the same result. In that case, just ORing it with the value seems more efficient than adding an "if" to check if the extension and DTE is enabled. Clément