Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1296920pxb; Fri, 21 Jan 2022 14:40:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJzY7+xtnGxOUZsuHZKh2ZYysCtSKWTiF1ZJEDw66GEfQ2uJrCEvsvBvIQXNSOiV5MZHpY5O X-Received: by 2002:a17:902:e844:b0:14a:ef67:ed96 with SMTP id t4-20020a170902e84400b0014aef67ed96mr5454287plg.104.1642804849600; Fri, 21 Jan 2022 14:40:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642804849; cv=none; d=google.com; s=arc-20160816; b=VjHfrc3hn8gmh0WyYYpJmfdyvBQ2I0bsFSnReE30KcDwWBdbWSp6EEgCrppAFTiJUm RVA8yrirnN69pJWptB8R7DI93sxxWVV1w5HA0gSe/qI9QmQeDcMeMqAjfbWcvzJiFMR+ 3tmggTZrzvRIZl69s7PhFhXJSSHZ5fpWWnU7Y0Nrt2/nhpUP+OwdqjPHLRkqPQT+rb5v bHRZ65bjDFoZ4jhRDAnBrYidI0j4ScyT8VIe5hiDoT7b3TbfTilWIcivim4XEA23IUcT 2VOhecE5MbCi95lvZMFKE1xW30uEGYeF1mcAGYIwJzdTy3FRyRb+R5dptVRq3xjD+cyr 9NKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=vRYuQT2WQHQUGRTTRZMYZKm7wq26OaWJh74t7a5J6a4=; b=ses88Tm9b98s+X3SWCKlV66wrKPitpv5+eAo62s5lpMF3GVSGlW6RVk5YKUjvOML8c MOEfaZRydjbUueZpFiMgWDf3SyiGynES+BnSuqIje1+UkZW3TeKW4rdemlzOEmqiAkJ3 WwSRrbfyCGSabDvHXabEE5ngCkPwQNCiozlHofJ2UnlnAgKMuMdXkzUTxThUpK24Hw3G Me6shWno9fkHFpLbHdqQSyFz6OngTf/4I38747sgjQlUqI+yvhiX7Sg6EWzfcwfDM43m zm8rrbD8/IOjYRShNPz8xEJL3YRbxJCVSOJExfXRMROYiAohSEDUXOCpWGyIG3RfmF0O T3hA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BtB1LxJl; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d184si7661834pgc.100.2022.01.21.14.40.34; Fri, 21 Jan 2022 14:40:49 -0800 (PST) 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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BtB1LxJl; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377742AbiATVN4 (ORCPT + 99 others); Thu, 20 Jan 2022 16:13:56 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:49384 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229568AbiATVNy (ORCPT ); Thu, 20 Jan 2022 16:13:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642713233; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=vRYuQT2WQHQUGRTTRZMYZKm7wq26OaWJh74t7a5J6a4=; b=BtB1LxJlQjlG0wi3il3hqzQvLE4PnbBrJ5HBOgVBFxNsro4iI968pqmXi4Y9pujdDaC9f4 cH94XgJXQ36Es4/jflnEEcdGmFQ4JWjTbQ0p+okEH4K05RPKY9/3cz90GjS1jZnJJc1Xrq nDmuhLp6yZYToLyhFHkw+5Q57Y0g5W0= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-335-yDXXbYudOPesGXYUTEhrRA-1; Thu, 20 Jan 2022 16:13:52 -0500 X-MC-Unique: yDXXbYudOPesGXYUTEhrRA-1 Received: by mail-qk1-f197.google.com with SMTP id u17-20020a05620a431100b004765c0dc33cso5131278qko.14 for ; Thu, 20 Jan 2022 13:13:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=vRYuQT2WQHQUGRTTRZMYZKm7wq26OaWJh74t7a5J6a4=; b=jIIBYIdyQk6MC/HvOjyKlzhIaHrpKO8MkokTZTaG98pld2WrHNX7wx924x+qcStAwz 2Aq5wtQB4V014dB1ILXq0k1cxMiSmGEIyNoXv4axhIC7hvm2xnm+DXT/RT8WexGB3DUL BGoBQX8Tafsfw3Otvh09BMvwDJa2OZfukRLrS9Vp5q55XSMxxtHyWGR/pvB+89DFKwfd vIo5nfJC1llvhQSkFl20PNFnmv7ZC4j47xXfT741RULkM0IGD4ct0/n9zdFNad0FlYIR SvdRxgZ5yZDDmeZxtURScfuNlKhV2dP96Xwh3zFsF3uOPM8ynQD0n71cIvXegzQZofWG YTJA== X-Gm-Message-State: AOAM531vCtgKIs1Ho6JIKEBfczxiKiYn7F1BrM5n0RDImkip4bkW8QNm 9/rcgZ0LreuJYOn8DJCA9Hjb3Dm/A92cYvxwItbs6MvDGi9nLvc83Yp2m6ql/0PeGN0OtEF+dIX PVj0Bt2H1+PoWrd5WjK6c0kK/ X-Received: by 2002:ac8:7d90:: with SMTP id c16mr862262qtd.306.1642713232005; Thu, 20 Jan 2022 13:13:52 -0800 (PST) X-Received: by 2002:ac8:7d90:: with SMTP id c16mr862230qtd.306.1642713231692; Thu, 20 Jan 2022 13:13:51 -0800 (PST) Received: from treble ([2600:1700:6e32:6c00::c]) by smtp.gmail.com with ESMTPSA id i142sm1943212qke.30.2022.01.20.13.13.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 13:13:51 -0800 (PST) Date: Thu, 20 Jan 2022 13:13:47 -0800 From: Josh Poimboeuf To: "Kirill A. Shutemov" Cc: bp@alien8.de, aarcange@redhat.com, ak@linux.intel.com, dan.j.williams@intel.com, dave.hansen@intel.com, david@redhat.com, hpa@zytor.com, jgross@suse.com, jmattson@google.com, joro@8bytes.org, kirill.shutemov@linux.intel.com, knsathya@kernel.org, linux-kernel@vger.kernel.org, luto@kernel.org, mingo@redhat.com, pbonzini@redhat.com, peterz@infradead.org, sathyanarayanan.kuppuswamy@linux.intel.com, sdeep@vmware.com, seanjc@google.com, tglx@linutronix.de, tony.luck@intel.com, vkuznets@redhat.com, wanpengli@tencent.com, x86@kernel.org Subject: Re: [PATCH 2/3] x86/boot: Allow to hook up alternative port I/O helpers Message-ID: <20220120211347.6gglputnh7n3wbvw@treble> References: <20220120021545.7786-1-kirill.shutemov@linux.intel.com> <20220120021545.7786-2-kirill.shutemov@linux.intel.com> <20220120163826.bits6ffbnbal4yse@box.shutemov.name> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20220120163826.bits6ffbnbal4yse@box.shutemov.name> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 20, 2022 at 07:38:26PM +0300, Kirill A. Shutemov wrote: > On Thu, Jan 20, 2022 at 05:15:43AM +0300, Kirill A. Shutemov wrote: > > diff --git a/arch/x86/boot/io.h b/arch/x86/boot/io.h > > new file mode 100644 > > index 000000000000..640daa3925fb > > --- /dev/null > > +++ b/arch/x86/boot/io.h > > @@ -0,0 +1,30 @@ > > +/* SPDX-License-Identifier: GPL-2.0 */ > > +#ifndef BOOT_IO_H > > +#define BOOT_IO_H > > + > > +#include > > + > > +struct port_io_ops { > > + unsigned char (*inb)(int port); > > + unsigned short (*inw)(int port); > > + unsigned int (*inl)(int port); > > + void (*outb)(unsigned char v, int port); > > + void (*outw)(unsigned short v, int port); > > + void (*outl)(unsigned int v, int port); > > +}; > > + > > +extern struct port_io_ops pio_ops; > > + > > +static inline void init_io_ops(void) > > +{ > > + pio_ops = (struct port_io_ops){ > > + .inb = inb, > > + .inw = inw, > > + .inl = inl, > > + .outb = outb, > > + .outw = outw, > > + .outl = outl, > > + }; > > +} > > + > > +#endif > > It works fine on x86-64, but breaks on i386: > > ld: Unexpected run-time relocations (.rel) detected! > > I'll change it to > > pio_ops.inb = inb; > pio_ops.inw = inw; > pio_ops.inl = inl; > pio_ops.outb = outb; > pio_ops.outw = outw; > pio_ops.outl = outl; > > It works, but I hate that I don't really have control here. I have no clue > why compiler generate different code after the change. It is very fragile. > > Do we really have no way to say compiler to avoid relactions here? This one: pio_ops = (struct port_io_ops){ .inb = inb, .inw = inw, .inl = inl, .outb = outb, .outw = outw, .outl = outl, }; .. actually allocates an anonymous struct in the .data section, which is memcpy'ed at runtime when the assignment occurs. That anonymous struct has .data -> .text relocations which have to be resolved at runtime because the distance between .data and .text isn't constant. The working version: pio_ops.inb = inb; pio_ops.inw = inw; pio_ops.inl = inl; pio_ops.outb = outb; pio_ops.outw = outw; pio_ops.outl = outl; ... only needs .text -> .text relocations which can be resolved at link time. -- Josh