Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1059984ybz; Thu, 16 Apr 2020 02:00:45 -0700 (PDT) X-Google-Smtp-Source: APiQypLshMQ0yFI9tGVjFq4BcQMmzRU+kUlunx48Xb8du1PW6O73KbH/z84G/32grXQqYp1P53yU X-Received: by 2002:a17:906:1490:: with SMTP id x16mr8105750ejc.323.1587027644859; Thu, 16 Apr 2020 02:00:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587027644; cv=none; d=google.com; s=arc-20160816; b=l+Cw7QXP7kO+BG/VHa6qbNnqKi6b97WI2Kg0OvQgzgjGARdy3Pudq/xRmu/fJYlbNq TpE2ne6SAOVv1/y5lowXj09/vl+26M68dHKvwzMuG2Jtes/ZQUbEv+T8Uv67oRdwkQCt NQdyMqmdp86J529boGiHwz7qhkb26vwmT0w0ZROFC92cHgmS/qMzkTGrREznCL/PjkmZ q+3AK5sdl9YMGRN+yzs6O15Vguhd/7kbCXko9+Y/YlFUTcdwuIJUfJL1cv0Y+TyW86af ddt5+nZjypUzAW6iT7B9kN3NdMaH7MOEDY+o9D3ES1/OS6r3KbH/sfHkdAbYOcbrxwkK /V8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date; bh=kqUnTllzepBKgiDbs/jUdnyGQ5LqQGfOMxVfZYso+fQ=; b=WxfiNWM7K38oX9KIfE9p91Wcuel3nWM1Pr7B6s44tnGWYjzMmKbxwzl0Ip9dZGfEr0 GpaOzURA09N+fzYXd/MTMS1rhQIxmu7pofwzo9IKDDS1tjdYilSkBjv/yDMBUmjR5865 /ep+q1gTWTorgPSnlGYqxkHyueqMafSKOu7kamQuapQFktlgovCtEjOl3FAtTimphJod ESN/yuOddIYeIPJojg7Tvo7xDAazbFPTI+Pf3RNTLRtHlo0dd719WTWR8mKLHp+vBFG+ 8HoCAosQCKb1e+VVxgMdHKpHTztI4MBzHe+3CvTh2se1wz3q2gxeOWqYk0pQhfooH1RW dbhQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x99si9463179ede.439.2020.04.16.02.00.22; Thu, 16 Apr 2020 02:00:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2503100AbgDPI6t (ORCPT + 99 others); Thu, 16 Apr 2020 04:58:49 -0400 Received: from mx2.suse.de ([195.135.220.15]:40456 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2502931AbgDPI4H (ORCPT ); Thu, 16 Apr 2020 04:56:07 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 3EB20AC4D; Thu, 16 Apr 2020 08:56:03 +0000 (UTC) Date: Thu, 16 Apr 2020 10:56:02 +0200 (CEST) From: Miroslav Benes To: Josh Poimboeuf cc: live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Zijlstra , Jessica Yu , linux-s390@vger.kernel.org, heiko.carstens@de.ibm.com Subject: Re: [PATCH 4/7] s390/module: Use s390_kernel_write() for relocations In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 14 Apr 2020, Josh Poimboeuf wrote: > From: Peter Zijlstra > > Instead of playing games with module_{dis,en}able_ro(), use existing > text poking mechanisms to apply relocations after module loading. > > So far only x86, s390 and Power have HAVE_LIVEPATCH but only the first > two also have STRICT_MODULE_RWX. > > This will allow removal of the last module_disable_ro() usage in > livepatch. The ultimate goal is to completely disallow making > executable mappings writable. > > [ jpoimboe: Split up patches. Use mod state to determine whether > memcpy() can be used. ] > > Cc: linux-s390@vger.kernel.org > Cc: heiko.carstens@de.ibm.com > Suggested-by: Josh Poimboeuf > Signed-off-by: Peter Zijlstra (Intel) > Signed-off-by: Josh Poimboeuf > --- > arch/s390/kernel/module.c | 106 ++++++++++++++++++++++---------------- > 1 file changed, 61 insertions(+), 45 deletions(-) > > diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c > index ba8f19bb438b..e85e378f876e 100644 > --- a/arch/s390/kernel/module.c > +++ b/arch/s390/kernel/module.c > @@ -174,7 +174,8 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs, > } > > static int apply_rela_bits(Elf_Addr loc, Elf_Addr val, > - int sign, int bits, int shift) > + int sign, int bits, int shift, > + void (*write)(void *dest, const void *src, size_t len)) > { > unsigned long umax; > long min, max; > @@ -194,26 +195,29 @@ static int apply_rela_bits(Elf_Addr loc, Elf_Addr val, > return -ENOEXEC; > } > > - if (bits == 8) > - *(unsigned char *) loc = val; > - else if (bits == 12) > - *(unsigned short *) loc = (val & 0xfff) | > + if (bits == 8) { > + write(loc, &val, 1); > + } else if (bits == 12) { > + unsigned short tmp = (val & 0xfff) | > (*(unsigned short *) loc & 0xf000); > - else if (bits == 16) > - *(unsigned short *) loc = val; > - else if (bits == 20) > - *(unsigned int *) loc = (val & 0xfff) << 16 | > - (val & 0xff000) >> 4 | > - (*(unsigned int *) loc & 0xf00000ff); > - else if (bits == 32) > - *(unsigned int *) loc = val; > - else if (bits == 64) > - *(unsigned long *) loc = val; > + write(loc, &tmp, 2); > + } else if (bits == 16) { > + write(loc, &val, 2); > + } else if (bits == 20) { > + unsigned int tmp = (val & 0xfff) << 16 | > + (val & 0xff000) >> 4 | (*(unsigned int *) loc & 0xf00000ff); > + write(loc, &tmp, 4); > + } else if (bits == 32) { > + write(loc, &val, 4); > + } else if (bits == 64) { > + write(loc, &val, 8); > + } > return 0; > } The compiler complains about the above changes arch/s390/kernel/module.c:199:9: warning: passing argument 1 of 'write' makes pointer from integer without a cast [-Wint-conversion] write(loc, &val, 1); ^~~ arch/s390/kernel/module.c:199:9: note: expected 'void *' but argument is of type 'Elf64_Addr' {aka 'long long unsigned int'} [...] > -int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab, > +static int __apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab, > unsigned int symindex, unsigned int relsec, > - struct module *me) > + struct module *me, > + void (*write)(void *dest, const void *src, size_t len)) > { > Elf_Addr base; > Elf_Sym *symtab; You also need to update apply_rela() call site in this function. It is missing write argument. > @@ -437,6 +442,17 @@ int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab, > return 0; > } > > +int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab, > + unsigned int symindex, unsigned int relsec, > + struct module *me) > +{ > + int ret; ret is unused; > + bool early = me->state == MODULE_STATE_UNFORMED; > + > + return __apply_relocate_add(sechdrs, strtab, symindex, relsec, me, > + early ? memcpy : s390_kernel_write); The compiler warns about arch/s390/kernel/module.c: In function 'apply_relocate_add': arch/s390/kernel/module.c:453:24: warning: pointer type mismatch in conditional expression early ? memcpy : s390_kernel_write); Miroslav