From patchwork Tue Sep 12 14:16:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13381772 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 837D7CA0EEC for ; Tue, 12 Sep 2023 14:18:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=m+ub3uoiLaxqybovPaZ7xQfc/0XZmovBLA9csxgjvlM=; b=t2DmjvIrI2KK2bjzz1dmAXTvHq rX8Ek/PEBd6X6xM0KSaEUwBU3q7F7O8WW0NaJxH6rS9jISCglW2hc/FO8378zSZmaiJrfPcyPTfSa 2vaDmJjJvt4PXXUEwrWjzyOPZZC6MzT/A2gYAyyJESgxLRYWY7d9RX6TM1TdGFOnXA96dsqtE7GHt snaj51Yv0xeiLjqLXSZBpAzIMxn2HbHWGE7AM4vPH4m8xBSyPwf5m00wbKbqDucsbXJUThieUReHg Je3ErChPrmOs4f6/2iQR3XLoleUdC5q//aHRXYzTCLgFA7CqDrmqkV60G/B05DesgzH7TEGZ08NH8 XTmPckIw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qg4DR-003WP6-0E; Tue, 12 Sep 2023 14:18:09 +0000 Received: from mail-wr1-x44a.google.com ([2a00:1450:4864:20::44a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qg4DC-003WAb-1w for linux-arm-kernel@lists.infradead.org; Tue, 12 Sep 2023 14:17:56 +0000 Received: by mail-wr1-x44a.google.com with SMTP id ffacd0b85a97d-31f3eaa5c5eso3751603f8f.3 for ; Tue, 12 Sep 2023 07:17:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1694528272; x=1695133072; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=hHYwcfo64DWIAT1yMYOXBOJJh5fY950vXfntgtoofFU=; b=IIGJ0/11/PpH/kqwhX091CWIC1PVRvCimAKrwScE+e7LIDwbrlYoFFitmM+Hr+hffr GfJrfLDDq+eXL84DJl7zbECusFjX3goARZ6M+4KJpniku+IYCTE3ADjiniRyvEJPVwYP VGFhq4K2MS1LkBTkJa/Vo0EAdbZ9+gvJkVSgXbByIULD2KpYp41+FelZp+z90GeEENu3 ZHbDY8ETTz0YUDt0LzaCxBz7pVsn/rFSTsDw/hOsg6shOjCxlsozVgMule5ri+9PP6f6 ZuhkVSIZHqsSrobdlekG4ZM46/2iU5q2f5KsqcVlFf7OX1axOcfoyEJ5fkq+TfurrhCD p5/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694528272; x=1695133072; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hHYwcfo64DWIAT1yMYOXBOJJh5fY950vXfntgtoofFU=; b=ip4ws40jTtZ4rYa3IuBeBgt2CO0fno1WH0PmqRiOAnU9pVS4COjM/C/gGr6vaL80hO gnw0l/ItXE+yh2EW4GanaxYYY/87MJJDLi6c3HCubwPwtndtRlkiijK/pv7kRiMg7fm5 4iaNPgrv6RFOjbT3tRQLN3X/RsOci4d/0xssiZfGjv/+ufjt//uijrE2zjBAOgHMB/Zz RhyJ0RO44gOm7ukjzpfiAgg0qGyyLwBkNdcCe1ve1Vqgi7BxoQxvxCePTT6OEEKHRsvt rwPy4AUpbVCDQWHSk+Yg5HXfNQnWiV8/G3nsrNcKeNu8IURYsjfmkQuUr4cqIWCavHkF Z+8A== X-Gm-Message-State: AOJu0Ywg3QHs94dSS2dzpGEBYSgthq3l9FkhYiLYLD9cDV+XW4y0LjfU Liu7St/spVwdybNbYYp3gfX4wH2rKWltarUGrUYUm7Td0Vfdu2sBXptnZfVAdYzZDfUL9ts+zsr qbHknDyWTuv34PO65Zg0q1rVm2e2fuN/uqhIuJ/cgfBvU13H/O3w1TfYUXUhY3kSAExUcqIh3x6 I= X-Google-Smtp-Source: AGHT+IELYFm2RlyeJmSe5h8QziYum/ySAT8PDWVFq9ML6m/Kbt/NSP0/wVURPIEroUf9iFjdy1lG+tnc X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a5d:660c:0:b0:317:5181:90ab with SMTP id n12-20020a5d660c000000b00317518190abmr152393wru.3.1694528272330; Tue, 12 Sep 2023 07:17:52 -0700 (PDT) Date: Tue, 12 Sep 2023 14:16:06 +0000 In-Reply-To: <20230912141549.278777-63-ardb@google.com> Mime-Version: 1.0 References: <20230912141549.278777-63-ardb@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=2763; i=ardb@kernel.org; h=from:subject; bh=CgRFQOMG2Yq3syft2Z3nHkoox+JzGIJN6TqHLAQ6JNc=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIZWhaNnuwo9iXEf2JQpk3dy1dd/VyKhgzrMVD30MD+2uv 8sVNGltRykLgxgHg6yYIovA7L/vdp6eKFXrPEsWZg4rE8gQBi5OAZiISgbDP3WOjAms3Sw7vs/i ufl06ZPZG6oVtfZcjzm+7y975wquozwM/zM3SKc+9eL7G6EWn80R6Zp01eHO99a6lKv1NtcX1ci yMAAA X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog Message-ID: <20230912141549.278777-79-ardb@google.com> Subject: [PATCH v4 16/61] arm64: idreg-override: Avoid parameq() and parameqn() From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Catalin Marinas , Will Deacon , Marc Zyngier , Mark Rutland , Ryan Roberts , Anshuman Khandual , Kees Cook , Joey Gouly X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230912_071754_685136_20026AC4 X-CRM114-Status: GOOD ( 19.88 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Ard Biesheuvel The only way parameq() and parameqn() deviate from the ordinary string and memory routines is that they ignore the difference between dashes and underscores. Since we copy each command line argument into a buffer before passing it to parameq() and parameqn() numerous times, let's just convert all dashes to underscores just once, and update the alias array accordingly. This also helps reduce the dependency on kernel APIs that are no longer available once we move this code into the early mini C runtime. Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/idreg-override.c | 28 ++++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/arch/arm64/kernel/idreg-override.c b/arch/arm64/kernel/idreg-override.c index 4e32a44560bf..cb4de31071d4 100644 --- a/arch/arm64/kernel/idreg-override.c +++ b/arch/arm64/kernel/idreg-override.c @@ -194,8 +194,8 @@ static const struct { char alias[FTR_ALIAS_NAME_LEN]; char feature[FTR_ALIAS_OPTION_LEN]; } aliases[] __initconst = { - { "kvm-arm.mode=nvhe", "id_aa64mmfr1.vh=0" }, - { "kvm-arm.mode=protected", "id_aa64mmfr1.vh=0" }, + { "kvm_arm.mode=nvhe", "id_aa64mmfr1.vh=0" }, + { "kvm_arm.mode=protected", "id_aa64mmfr1.vh=0" }, { "arm64.nosve", "id_aa64pfr0.sve=0" }, { "arm64.nosme", "id_aa64pfr1.sme=0" }, { "arm64.nobti", "id_aa64pfr1.bt=0" }, @@ -224,7 +224,7 @@ static int __init find_field(const char *cmdline, len = snprintf(opt, ARRAY_SIZE(opt), "%s.%s=", reg->name, reg->fields[f].name); - if (!parameqn(cmdline, opt, len)) + if (memcmp(cmdline, opt, len)) return -1; return kstrtou64(cmdline + len, 0, v); @@ -281,23 +281,29 @@ static __init void __parse_cmdline(const char *cmdline, bool parse_aliases) cmdline = skip_spaces(cmdline); - for (len = 0; cmdline[len] && !isspace(cmdline[len]); len++); - if (!len) + /* terminate on "--" appearing on the command line by itself */ + if (cmdline[0] == '-' && cmdline[1] == '-' && isspace(cmdline[2])) return; - len = min(len, ARRAY_SIZE(buf) - 1); - memcpy(buf, cmdline, len); - buf[len] = '\0'; - - if (strcmp(buf, "--") == 0) + for (len = 0; cmdline[len] && !isspace(cmdline[len]); len++) { + if (len >= sizeof(buf) - 1) + break; + if (cmdline[len] == '-') + buf[len] = '_'; + else + buf[len] = cmdline[len]; + } + if (!len) return; + buf[len] = 0; + cmdline += len; match_options(buf); for (i = 0; parse_aliases && i < ARRAY_SIZE(aliases); i++) - if (parameq(buf, aliases[i].alias)) + if (!memcmp(buf, aliases[i].alias, len + 1)) __parse_cmdline(aliases[i].feature, false); } while (1); }