mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kristina Martsenko <kristina.martsenko@arm.com>
To: Colton Lewis <coltonlewis@google.com>
Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>, Marc Zyngier <maz@kernel.org>,
	Oliver Upton <oliver.upton@linux.dev>,
	James Morse <james.morse@arm.com>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	Zenghui Yu <yuzenghui@huawei.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Mark Brown <broonie@kernel.org>,
	Luis Machado <luis.machado@arm.com>,
	Vladimir Murzin <vladimir.murzin@arm.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 07/11] arm64: mops: handle MOPS exceptions
Date: Tue, 30 May 2023 17:36:18 +0100	[thread overview]
Message-ID: <64701978-1b11-3dec-c0e4-57f1a0eee1fe@arm.com> (raw)
In-Reply-To: <gsnta5xsb36u.fsf@coltonlewis-kvm.c.googlers.com>

On 25/05/2023 20:50, Colton Lewis wrote:
>> +    if (esr & ESR_ELx_MOPS_ISS_MEM_INST) {
>> +        /* SET* instruction */
>> +        if (option_a ^ wrong_option) {
>> +            /* Format is from Option A; forward set */
>> +            pt_regs_write_reg(regs, dstreg, dst + size);
>> +            pt_regs_write_reg(regs, sizereg, -size);
>> +        }
>> +    } else {
>> +        /* CPY* instruction */
>> +        if (!(option_a ^ wrong_option)) {
>> +            /* Format is from Option B */
>> +            if (regs->pstate & PSR_N_BIT) {
>> +                /* Backward copy */
>> +                pt_regs_write_reg(regs, dstreg, dst - size);
>> +                pt_regs_write_reg(regs, srcreg, src - size);
>> +            }
>> +        } else {
>> +            /* Format is from Option A */
>> +            if (size & BIT(63)) {
>> +                /* Forward copy */
>> +                pt_regs_write_reg(regs, dstreg, dst + size);
>> +                pt_regs_write_reg(regs, srcreg, src + size);
>> +                pt_regs_write_reg(regs, sizereg, -size);
>> +            }
>> +        }
>> +    }
> 
> I can see an argument for styling things closely to the ARM manual as
> you have done here, but Linux style recommends against deep nesting. In
> this case it is unneeded. I believe this can be written as a single
> if-else chain and that makes it easier to distinguish the three options.
> 
> if ((esr & ESR_ELx_MOPS_ISS_MEM_INST) && (option_a ^ wrong_option)) {
>     /* Format is from Option A; forward set */
>     pt_regs_write_reg(regs, dstreg, dst + size);
>     pt_regs_write_reg(regs, sizereg, -size);
> } else if ((option_a ^ wrong_option) && (size & BIT(63)) {
>     /* Forward copy */
>     pt_regs_write_reg(regs, dstreg, dst + size);
>     pt_regs_write_reg(regs, srcreg, src + size);
>     pt_regs_write_reg(regs, sizereg, -size);
> } else if (regs-pstate & PSR_N_BIT) {
>     /* Backward copy */
>     pt_regs_write_reg(regs, dstreg, dst - size);
>     pt_regs_write_reg(regs, srcreg, src - size);
> }

Yeah, the nesting gets a bit deep here, but there are 6 cases in total, ie 6 
ways the hardware can set up the registers and pstate (in 3 of them the kernel
doesn't need to modify the registers), and I think the current structure makes
it clearer what the 6 are, so I'd prefer to keep it as it is for now.

Thanks,
Kristina


  reply	other threads:[~2023-05-30 16:36 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-09 14:22 [PATCH v2 00/11] arm64: Support for Armv8.8 memcpy instructions in userspace Kristina Martsenko
2023-05-09 14:22 ` [PATCH v2 01/11] KVM: arm64: initialize HCRX_EL2 Kristina Martsenko
2023-06-02 13:49   ` Catalin Marinas
2023-06-05 15:41     ` Oliver Upton
2023-06-03  8:39   ` Marc Zyngier
2023-05-09 14:22 ` [PATCH v2 02/11] arm64: cpufeature: detect FEAT_HCX Kristina Martsenko
2023-05-09 14:22 ` [PATCH v2 03/11] KVM: arm64: switch HCRX_EL2 between host and guest Kristina Martsenko
2023-06-02 13:51   ` Catalin Marinas
2023-06-05 15:41     ` Oliver Upton
2023-06-03  8:40   ` Marc Zyngier
2023-05-09 14:22 ` [PATCH v2 04/11] arm64: mops: document boot requirements for MOPS Kristina Martsenko
2023-05-09 14:22 ` [PATCH v2 05/11] arm64: mops: don't disable host MOPS instructions from EL2 Kristina Martsenko
2023-05-09 14:22 ` [PATCH v2 06/11] KVM: arm64: hide MOPS from guests Kristina Martsenko
2023-05-25 19:26   ` Colton Lewis
2023-05-30 16:34     ` Kristina Martsenko
2023-06-03  8:42   ` Marc Zyngier
2023-06-05 15:45     ` Oliver Upton
2023-05-09 14:22 ` [PATCH v2 07/11] arm64: mops: handle MOPS exceptions Kristina Martsenko
2023-05-25 19:50   ` Colton Lewis
2023-05-30 16:36     ` Kristina Martsenko [this message]
2023-06-05 11:43   ` Shaoqin Huang
2023-06-05 12:04     ` Catalin Marinas
2023-05-09 14:22 ` [PATCH v2 08/11] arm64: mops: handle single stepping after MOPS exception Kristina Martsenko
2023-05-09 14:22 ` [PATCH v2 09/11] arm64: mops: detect and enable FEAT_MOPS Kristina Martsenko
2023-05-09 14:22 ` [PATCH v2 10/11] arm64: mops: allow disabling MOPS from the kernel command line Kristina Martsenko
2023-05-09 14:22 ` [PATCH v2 11/11] kselftest/arm64: add MOPS to hwcap test Kristina Martsenko
2023-05-12  4:02   ` Mark Brown
2023-06-05 17:46 ` [PATCH v2 00/11] arm64: Support for Armv8.8 memcpy instructions in userspace Catalin Marinas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=64701978-1b11-3dec-c0e4-57f1a0eee1fe@arm.com \
    --to=kristina.martsenko@arm.com \
    --cc=broonie@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=coltonlewis@google.com \
    --cc=james.morse@arm.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luis.machado@arm.com \
    --cc=mark.rutland@arm.com \
    --cc=maz@kernel.org \
    --cc=oliver.upton@linux.dev \
    --cc=suzuki.poulose@arm.com \
    --cc=vladimir.murzin@arm.com \
    --cc=will@kernel.org \
    --cc=yuzenghui@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®