From patchwork Tue Oct 23 21:34:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Stoppa X-Patchwork-Id: 10653701 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5160B14BB for ; Tue, 23 Oct 2018 21:36:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A1C82A3C7 for ; Tue, 23 Oct 2018 21:36:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2D6842A3CD; Tue, 23 Oct 2018 21:36:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B2FA2A3C7 for ; Tue, 23 Oct 2018 21:36:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0442B6B0007; Tue, 23 Oct 2018 17:36:08 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id EB32B6B000D; Tue, 23 Oct 2018 17:36:07 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D2AF76B000E; Tue, 23 Oct 2018 17:36:07 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-lj1-f200.google.com (mail-lj1-f200.google.com [209.85.208.200]) by kanga.kvack.org (Postfix) with ESMTP id 5FF796B0007 for ; Tue, 23 Oct 2018 17:36:07 -0400 (EDT) Received: by mail-lj1-f200.google.com with SMTP id s7-v6so995183ljh.3 for ; Tue, 23 Oct 2018 14:36:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:reply-to; bh=9TeBZENTG4lUlljtOFNGnausIJ9loexqClGDhlY00q0=; b=A355ojvNJ9956vTCCcTb4G9dr0hu6Qun82+bS4D5B09EP3x2GRXrQhgKpYGV7HqqsM 3hU8lL9yAD3DhjzdVzf2PpSOqHH39OwYkG+8dUwBY5cR/O3w21P73zqD2K73i2+OKBCI 5GvZTBAVLBA3AWeX87I2QUK1X/7eHCmFyDA/nqgCYB5vwFlY2qFNroVrK2u90JoNZUig cm8ZTRHJ1+wCsFUAOJdgSan1gSrnYx6R+lCPD2GS/p6SRQ6Dpa55CwD26IbhS1L8YwJb fH1jNiJ2/+LMhu2WBYDYXoiZXFQUQfiEYxV3FenBPSui2BZ80QqhMiFA0WFEcSWXavh1 P0jQ== X-Gm-Message-State: ABuFfog4UPvEvJXbAzE82396cR4sXBa026T75voKEs51g6Y0q31q5eYB 6K+eIfoXLcmHU3r7n83T62MTMXz9nJyiIEkfzv2i3n1bz7/HHZZek0r+67G9L9aeuh2phTjsFD7 ZCH9MtvcmAWfewGIvokKqole9czpP+v7gVW9k/sC3io4qX40GydT20g7GLEpklu4kdP/GNeCLNi 5acA7X+YkYYeNwylKwUp83RHDcmr020iTWcyB9Wl/AbRdMIQJDR5MF/viIqlyaukSoLg7N5EF6W B1gkx/Pz9259cE+9jDVbD/wNvfRC0Rf7hSJaNH0WME1sNBJktBZ4fVMSZ9Pj0ptb97ysigJB/hZ ApGySrhYeExBC3bB5i1/95xb9nwcxrlM4TxmQLcSu+G/YZa/UXJnZF8gpP9+Gw/Os15iV/+KnRl B X-Received: by 2002:a19:9844:: with SMTP id a65-v6mr14016441lfe.63.1540330566617; Tue, 23 Oct 2018 14:36:06 -0700 (PDT) X-Received: by 2002:a19:9844:: with SMTP id a65-v6mr14016380lfe.63.1540330564939; Tue, 23 Oct 2018 14:36:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540330564; cv=none; d=google.com; s=arc-20160816; b=JE8sHpoqhO1/1pWytriOwEu+ju+2HMMsG80iPwntB0oXebTyGh+pnEWQaJgSQ19ygm BuuSFroqTFZJnqC9xz528Pic1WH6EBRVGfwE4wADBK7ALmXFwMA0GB4PbKNzMnV3G88N wcld/p5rJWZdwa42+LnGEMAe/JgrYjti0GX8/mN/cM7NDDhQc7mkKZsc1paI/DF4dEy5 OizzQU9f42ZaVNdBBJly8zWd8xJB4OsE8SY45QE1IZ05uFVcC7cIejgmRT6JoDmUlHpD ScweerTAyQLQDc6DHVQRbvd31R96yCwxi6Kagp9fY8R9f1WVMibhb1fhI6YCCLXKLfx4 Slfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=reply-to:references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9TeBZENTG4lUlljtOFNGnausIJ9loexqClGDhlY00q0=; b=X1o1gH51BK6LyO0jO1c1gIoP+rDRbaUgOwywjrSkQ4CBd455MSlcqrmBgA3iLITh3H LDD0K4deSF3zE0OjBwYkVZnbMaimArlIjbVTfg/xzw9RokrBk9AglMKI5v0knQceubGS GxhOB4kbhzmS7eF/THC3cLOFx53xLbl8MX85QBAFhP7blkV4R4wNBnqCg/3TxLx7T/cm 9dfPTjrJW74XOzf2mp3IJU4TZ8dtzTY8XKKHPrkkBd7e+4Zz4ASpHNNvs1wuHQ2r/lMb J5Fsw6rvlmbJN7UNp8WC+SetwUmDUZe+iluuECHIibY2yy3MNNWS3A9OTcHnMl/5nqaM /WjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JtoyO3mZ; spf=pass (google.com: domain of igor.stoppa@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=igor.stoppa@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id x14-v6sor1728479ljh.27.2018.10.23.14.36.04 for (Google Transport Security); Tue, 23 Oct 2018 14:36:04 -0700 (PDT) Received-SPF: pass (google.com: domain of igor.stoppa@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JtoyO3mZ; spf=pass (google.com: domain of igor.stoppa@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=igor.stoppa@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to; bh=9TeBZENTG4lUlljtOFNGnausIJ9loexqClGDhlY00q0=; b=JtoyO3mZ13IGzAbCIgy6S5RYsmImtY6hfg34KQRQ2X3TR1VVri5yBZ/LUjBcD0TzXa 0s8L1kB/YwwSuVWbA3820PquvwCu3SkJCcO1geuaAaOGfUNh9JAvXkHX3kScSRePUVzs LpBgTT1JYuKJ1aT49DAJUFExgxQPahyLwVz4BPku8ogRZBoPGO9RswhALPMjDi8XbttO OjGxJeSt7f0J7GWI7q5EdlapOM+CLE2SPmDyplRRclUZ20Yaw/5nyVtaOA6eSk9/RtMb rtjjIO80ygFKzuE+VuAYK60mF+XSs2WkRVh4yBh7Fgr9V0xTBNIf9zkz+/Qr1wr90r6X Paxg== X-Google-Smtp-Source: AJdET5fm/SfTwnUQw/H/6N0AMH3Waqo8igwVte/fLnkcWUycwtZsZmlgduLgWV39YuSoalp0uJ0pjw== X-Received: by 2002:a2e:84c5:: with SMTP id q5-v6mr5777858ljh.65.1540330564560; Tue, 23 Oct 2018 14:36:04 -0700 (PDT) Received: from localhost.localdomain (91-159-62-169.elisa-laajakaista.fi. [91.159.62.169]) by smtp.gmail.com with ESMTPSA id y127-v6sm377950lfc.13.2018.10.23.14.36.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Oct 2018 14:36:03 -0700 (PDT) From: Igor Stoppa X-Google-Original-From: Igor Stoppa To: Mimi Zohar , Kees Cook , Matthew Wilcox , Dave Chinner , James Morris , Michal Hocko , kernel-hardening@lists.openwall.com, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org Cc: igor.stoppa@huawei.com, Dave Hansen , Jonathan Corbet , Laura Abbott , Vlastimil Babka , "Kirill A. Shutemov" , Andrew Morton , Pavel Tatashin , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 05/17] prmem: shorthands for write rare on common types Date: Wed, 24 Oct 2018 00:34:52 +0300 Message-Id: <20181023213504.28905-6-igor.stoppa@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181023213504.28905-1-igor.stoppa@huawei.com> References: <20181023213504.28905-1-igor.stoppa@huawei.com> Reply-To: Igor Stoppa X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Wrappers around the basic write rare functionality, addressing several common data types found in the kernel, allowing to specify the new values through immediates, like constants and defines. Note: The list is not complete and could be expanded. Signed-off-by: Igor Stoppa CC: Michal Hocko CC: Vlastimil Babka CC: "Kirill A. Shutemov" CC: Andrew Morton CC: Pavel Tatashin CC: linux-mm@kvack.org CC: linux-kernel@vger.kernel.org --- MAINTAINERS | 1 + include/linux/prmemextra.h | 133 +++++++++++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 include/linux/prmemextra.h diff --git a/MAINTAINERS b/MAINTAINERS index e566c5d09faf..df7221eca160 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -9459,6 +9459,7 @@ M: Igor Stoppa L: kernel-hardening@lists.openwall.com S: Maintained F: include/linux/prmem.h +F: include/linux/prmemextra.h F: mm/prmem.c MEMORY MANAGEMENT diff --git a/include/linux/prmemextra.h b/include/linux/prmemextra.h new file mode 100644 index 000000000000..36995717720e --- /dev/null +++ b/include/linux/prmemextra.h @@ -0,0 +1,133 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * prmemextra.h: Shorthands for write rare of basic data types + * + * (C) Copyright 2018 Huawei Technologies Co. Ltd. + * Author: Igor Stoppa + * + */ + +#ifndef _LINUX_PRMEMEXTRA_H +#define _LINUX_PRMEMEXTRA_H + +#include + +/** + * wr_char - alters a char in write rare memory + * @dst: target for write + * @val: new value + * + * Returns true on success, false otherwise. + */ +static __always_inline +bool wr_char(const char *dst, const char val) +{ + return wr_memcpy(dst, &val, sizeof(val)); +} + +/** + * wr_short - alters a short in write rare memory + * @dst: target for write + * @val: new value + * + * Returns true on success, false otherwise. + */ +static __always_inline +bool wr_short(const short *dst, const short val) +{ + return wr_memcpy(dst, &val, sizeof(val)); +} + +/** + * wr_ushort - alters an unsigned short in write rare memory + * @dst: target for write + * @val: new value + * + * Returns true on success, false otherwise. + */ +static __always_inline +bool wr_ushort(const unsigned short *dst, const unsigned short val) +{ + return wr_memcpy(dst, &val, sizeof(val)); +} + +/** + * wr_int - alters an int in write rare memory + * @dst: target for write + * @val: new value + * + * Returns true on success, false otherwise. + */ +static __always_inline +bool wr_int(const int *dst, const int val) +{ + return wr_memcpy(dst, &val, sizeof(val)); +} + +/** + * wr_uint - alters an unsigned int in write rare memory + * @dst: target for write + * @val: new value + * + * Returns true on success, false otherwise. + */ +static __always_inline +bool wr_uint(const unsigned int *dst, const unsigned int val) +{ + return wr_memcpy(dst, &val, sizeof(val)); +} + +/** + * wr_long - alters a long in write rare memory + * @dst: target for write + * @val: new value + * + * Returns true on success, false otherwise. + */ +static __always_inline +bool wr_long(const long *dst, const long val) +{ + return wr_memcpy(dst, &val, sizeof(val)); +} + +/** + * wr_ulong - alters an unsigned long in write rare memory + * @dst: target for write + * @val: new value + * + * Returns true on success, false otherwise. + */ +static __always_inline +bool wr_ulong(const unsigned long *dst, const unsigned long val) +{ + return wr_memcpy(dst, &val, sizeof(val)); +} + +/** + * wr_longlong - alters a long long in write rare memory + * @dst: target for write + * @val: new value + * + * Returns true on success, false otherwise. + */ +static __always_inline +bool wr_longlong(const long long *dst, const long long val) +{ + return wr_memcpy(dst, &val, sizeof(val)); +} + +/** + * wr_ulonglong - alters an unsigned long long in write rare memory + * @dst: target for write + * @val: new value + * + * Returns true on success, false otherwise. + */ +static __always_inline +bool wr_ulonglong(const unsigned long long *dst, + const unsigned long long val) +{ + return wr_memcpy(dst, &val, sizeof(val)); +} + +#endif