From patchwork Fri Jan 13 18:03:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 43536 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp416179wrt; Fri, 13 Jan 2023 10:19:24 -0800 (PST) X-Google-Smtp-Source: AMrXdXuaTsLK9L58DbIqeDLhUvYIeabkOuA84cZsdKEhaapMY0GEKf78IG/Y7Gez4OFMeEZ75YZi X-Received: by 2002:a05:6a00:1f19:b0:58b:451f:bf53 with SMTP id be25-20020a056a001f1900b0058b451fbf53mr10782808pfb.5.1673633964382; Fri, 13 Jan 2023 10:19:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673633964; cv=none; d=google.com; s=arc-20160816; b=aJ5O/km224npbTr49HfTrd9I7DoKdmsP1UH+WMac5D6FNIEg/BUoCO3ba6C/TueCGG wMOzuk6pKkIwlyDzJJn/JB/f8HjAARyPygXNrJqb92kwOS6kEMcWb/a930U2lDiXQRhN Pqze1vAdFB+FAL0qK/1awAcnuCx1XeqZ9YcugCVEnfejsb4kVV7gt5OEszg/YAZ3N3g8 g0hF/HqCwhWAvZ0Kn/Yn48Si2L0hrDe7Ztsz7PJznhzERhYzKh7slIlG1YcOKoj5oJRx CQKAMMh4Q5RqMaJDZkZTTa9PCjsVwEbJml3Eow2Lj7XcUI3Je7T2c9UkQT483WUx+gM7 GgXQ== 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=TE9/JcNb2iulFWfIDzdiRr+9nen9Xt0XGhINGFEM7a0=; b=KkttuaE+X2tfoEHJ9a6JZ/qZM2qPXuCD/ZBZxIhPHrhPbNC5eNONuWtev+mtUC1nQ4 d1g4ulzlXGQNPkEaPxsPKHwtL/OZjXhTgBLmOmXbWSUkUVwHVsufv9TB/7Yv4gGUBkZ2 O+zTJ4Mk6evT80WvNpLvK3c1mSIytJ9Owml8dH7ueW/kjFtmiq1fY6gzg7fDpF/hOEfc sBIxgfhs/X7efs04XQpWU59BIzTgHQnpxsh0EB/kKHdQiBKRDjpMmOZdyojVxY3kmrcv IgzsmS2Xamy3uu+5A7bVHJja0kOv+6Qa5A8I4c1j7ltzeJUV/S46ds6mudn1sDCTYj4M sCJA== 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=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bq6-20020a056a000e0600b0058b99b54b31si7005233pfb.125.2023.01.13.10.19.02; Fri, 13 Jan 2023 10:19:24 -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=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229463AbjAMSNy (ORCPT + 99 others); Fri, 13 Jan 2023 13:13:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230174AbjAMSNN (ORCPT ); Fri, 13 Jan 2023 13:13:13 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 74256A702B; Fri, 13 Jan 2023 10:05:16 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 08C72176C; Fri, 13 Jan 2023 10:05:04 -0800 (PST) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 01F653F67D; Fri, 13 Jan 2023 10:04:19 -0800 (PST) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org Cc: catalin.marinas@arm.com, lenb@kernel.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, mark.rutland@arm.com, mhiramat@kernel.org, ndesaulniers@google.com, ojeda@kernel.org, peterz@infradead.org, rafael.j.wysocki@intel.com, revest@chromium.org, robert.moore@intel.com, rostedt@goodmis.org, will@kernel.org Subject: [PATCH v2 6/8] arm64: patching: Add aarch64_insn_write_literal_u64() Date: Fri, 13 Jan 2023 18:03:53 +0000 Message-Id: <20230113180355.2930042-7-mark.rutland@arm.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230113180355.2930042-1-mark.rutland@arm.com> References: <20230113180355.2930042-1-mark.rutland@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham 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?1754932407481396102?= X-GMAIL-MSGID: =?utf-8?q?1754932407481396102?= In subsequent patches we'll need to atomically write to a naturally-aligned 64-bit literal embedded within the kernel text. Add a helper for this. For consistency with other text patching code we use copy_to_kernel_nofault(), which is atomic for naturally-aligned accesses up to 64-bits. Signed-off-by: Mark Rutland Cc: Catalin Marinas Cc: Florent Revest Cc: Masami Hiramatsu Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Will Deacon --- arch/arm64/include/asm/patching.h | 2 ++ arch/arm64/kernel/patching.c | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/arch/arm64/include/asm/patching.h b/arch/arm64/include/asm/patching.h index 6bf5adc56295..68908b82b168 100644 --- a/arch/arm64/include/asm/patching.h +++ b/arch/arm64/include/asm/patching.h @@ -7,6 +7,8 @@ int aarch64_insn_read(void *addr, u32 *insnp); int aarch64_insn_write(void *addr, u32 insn); +int aarch64_insn_write_literal_u64(void *addr, u64 val); + int aarch64_insn_patch_text_nosync(void *addr, u32 insn); int aarch64_insn_patch_text(void *addrs[], u32 insns[], int cnt); diff --git a/arch/arm64/kernel/patching.c b/arch/arm64/kernel/patching.c index 33e0fabc0b79..b4835f6d594b 100644 --- a/arch/arm64/kernel/patching.c +++ b/arch/arm64/kernel/patching.c @@ -88,6 +88,23 @@ int __kprobes aarch64_insn_write(void *addr, u32 insn) return __aarch64_insn_write(addr, cpu_to_le32(insn)); } +noinstr int aarch64_insn_write_literal_u64(void *addr, u64 val) +{ + u64 *waddr; + unsigned long flags; + int ret; + + raw_spin_lock_irqsave(&patch_lock, flags); + waddr = patch_map(addr, FIX_TEXT_POKE0); + + ret = copy_to_kernel_nofault(waddr, &val, sizeof(val)); + + patch_unmap(FIX_TEXT_POKE0); + raw_spin_unlock_irqrestore(&patch_lock, flags); + + return ret; +} + int __kprobes aarch64_insn_patch_text_nosync(void *addr, u32 insn) { u32 *tp = addr;